微信公众号搜"智元新知"关注
微信扫一扫可直接关注哦!

Winforms组合框设置默认选定值不起作用

如何解决Winforms组合框设置默认选定值不起作用

我正在使用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;

版权声明:本文内容由互联网用户自发贡献,该文观点与技术仅代表作者本人。本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌侵权/违法违规的内容, 请发送邮件至 dio@foxmail.com 举报,一经查实,本站将立刻删除。