开发者

wpf combobox display 1st item from list

开发者 https://www.devze.com 2023-03-28 22:42 出处:网络
i have a combobox bou开发者_JAVA技巧nd to an ObservableCollection:- <ComboBox Name=\"combo\" ItemsSource=\"{Binding Things}\" SelectionChanged=\"ComboBox_SelectionChanged\" >

i have a combobox bou开发者_JAVA技巧nd to an ObservableCollection:-

<ComboBox Name="combo" ItemsSource="{Binding Things}" SelectionChanged="ComboBox_SelectionChanged" >

in the code behind I have

Dim thingArray = New ObservableCollection(Of Things)   
Me.combo.DataContext = Me.thingArray

Assume thingArray is initialized to 5 Thing objects and Thing has a toString() implementation. I want to display the first item Thing(0) by default on the ComboBox. How do i do that?


If Me.thingArray.Count > 0 Then Me.combo.SelectedIndex = 0

0

精彩评论

暂无评论...
验证码 换一张
取 消