I have to force my combobox to change the selected index when user enters text and there is an item match. Right now i am getting the item match from my combobox like this:
List<DataRowView> deliveryRoutes = ((ComboBox)sender).Items.Cast<DataRowView>().ToList();
if (deliveryRoutes.Where(q => q.Row[0].ToString().ToLower().Equals(((ComboBox)sender).Text.ToLower())).Count() != 0)
{
}
This code checks if the user input is a match with the combobox datasource. in my if statement i want to set the selected index of my combobox to be the matched text. Like so:
DeliveryRouteID.SelectedIndex = matchedTextIndex
I have tried getting the index from this without any luck:
deliveryRoutes.Where(q => q.Row[0].ToString().ToLower().Equals(((ComboBox)sender).Text.ToLower())).FirstOrDefault().Row[0]
How would i get the index and set it to be the selected index ?
您正在寻找ComboBox.FindStringExact或ComboBox.FindString
cmb.SelectedIndex = cmb.FindStringExact(item);
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.