Create a Form, add a combobox in it, then paste :
private void Form1_Load(object se开发者_Python百科nder, EventArgs e)
{
TimeZoneInfo myZome = TimeZoneInfo.Local;
comboBox1.DataSource = TimeZoneInfo.GetSystemTimeZones();
comboBox1.SelectedItem = myZome;
}
ComboBox will display only the first element, it does not care about selectedItem... this driving me nuts any help please ? Thanks in advance Fred
The instance of your timezone object (myZome) is not in the zones list. Find the right one in the collection.
Try this:
private void Form1_Load(object sender, EventArgs e)
{
ICollection<TimeZoneInfo> zoneList = TimeZoneInfo.GetSystemTimeZones();
TimeZoneInfo myZone = zoneList.First<TimeZoneInfo>(t => t.Id == TimeZoneInfo.Local.Id);
comboBox1.DataSource = zoneList;
comboBox1.SelectedItem = myZone;
}
精彩评论