1
因此,我正在使用所有計算機時區填充組合框,然後默認選擇本地時區。我可以填充組合框,但選擇默認項目讓我感到困惑。將TimeZoneInfo添加到組合框並將SeletedItem設置爲擋住我
'load up the combobox with all time zones
Dim tzCollection As ReadOnlyCollection(Of TimeZoneInfo) = TimeZoneInfo.GetSystemTimeZones()
cboClockTmZone1.DataSource = tzCollection
'the computers local time zone
Dim myZone As TimeZoneInfo = TimeZoneInfo.Local
'get the index of the local time zone in the collections
Dim idx As Integer = tzCollection.IndexOf(myZone)
Dim qdx As Integer = cboClockTmZone1.Items.IndexOf(myZone)
'set the time zone
'cboClockTmZone1.SelectedIndex = idx 'this works
cboClockTmZone1.SelectedIndex = qdx 'this does not
因此,也許我對這一點缺乏理解,但是當我將集合綁定到組合框時,它沒有被TimeZoneInfo對象填充。換句話說,不是每個TimeZoneInfo類型的列表項目?如果是這樣,爲什麼qdx分配不起作用?我得到-1這意味着它無法在組合框中找到時區對象,但它可以在tzCollection中找到它。我也嘗試過.SelectedItem,但那也沒有完成。
我只是不理解這應該如何工作。它現在可以工作,因爲我認爲從tzCollection到cbo項目有一對一的映射關係。但是如果有人能夠對這兩種方法有所瞭解,那麼我可以更好地理解,我將不勝感激。
聽起來像某人忘了單元測試! – IAbstract 2012-03-17 00:08:58
因此,我正在做的是有沒有其他更有利的解決方法? – sinDizzy 2012-03-17 00:59:06
你對我看起來相當不錯。 – 2012-03-17 01:14:27