[英]Force index selection on combobox when item match C#
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. 在我的if语句中,我想将我的组合框的选定索引设置为匹配的文本。 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);
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.