开发者

How to fix ComboBox index issue in C#

开发者 https://www.devze.com 2023-04-05 16:41 出处:网络
I wrote a WPF application in which my ComboBox.Items.IndexOf(ItemName); giving -1 even though Item is present in the ComboBox items list. Can anybody please help me to get the solution.开发者_开发百科

I wrote a WPF application in which my ComboBox.Items.IndexOf(ItemName); giving -1 even though Item is present in the ComboBox items list. Can anybody please help me to get the solution.开发者_开发百科

Thanks in advance


.IndexOf is looking for the object in the items collection rather than looking for it by name (which is what you are indicating that you want to do). You should use ComboBox.FindStringExact("ItemName") to get what you require.


I do believe that this is how you set the list to blank, hence the " - " before the 1, indicating that it's below the 0 threshold which items begin to be indexed.

0

精彩评论

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