0

我正在使用 Bunifu UI winforms,我正在尝试为组合框设置默认值,但我的代码不起作用,我尝试使用 selectedIndex 属性设置它,但没有任何反应。有人能帮我吗?谢谢!

ReadOnlyCollection<TimeZoneInfo> timeZones = TimeZoneInfo.GetSystemTimeZones();
        TimeZoneInfo currentTimeZone = TimeZoneInfo.FindSystemTimeZoneById(TimeZone.CurrentTimeZone.StandardName);
        Dictionary<int, string> dic = new Dictionary<int, string>();
        dic.Add(0, "Choose Timezone");
        foreach (var item in timeZones)
        {
            int time = (item.BaseUtcOffset.Hours * 60 + item.BaseUtcOffset.Minutes) * 60;
            if (!dic.ContainsKey(time))
            {
                dic.Add(time, (time == 0) ? item.DisplayName.Substring(0, 5) : item.DisplayName.Substring(0, 11));
            }
        }

        TimeZoneDropdown.DataSource = dic.ToList();
        TimeZoneDropdown.DisplayMember = "Value";
        TimeZoneDropdown.ValueMember = "Key";
        TimeZoneDropdown.SelectedValue = (!String.IsNullOrEmpty(Configs.GetValue("TimeZone"))) ? Convert.ToInt32(Configs.GetValue("TimeZone")) : (currentTimeZone.BaseUtcOffset.Hours * 60 + currentTimeZone.BaseUtcOffset.Minutes) * 60;
4

0 回答 0