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
Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.
Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.
Lost your password? Please enter your email address. You will receive a link and will create a new password via email.
Please briefly explain why you feel this question should be reported.
Please briefly explain why you feel this answer should be reported.
Please briefly explain why you feel this user should be reported.
.IndexOfis 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 useComboBox.FindStringExact("ItemName")to get what you require.