【发布时间】:2019-08-13 06:44:29
【问题描述】:
我正在开发一个应用程序,需要使用包含而不是 StartsWith 来搜索组合框,无法绑定显示成员。
试图将它直接绑定到类,但没有运气。
private void customersDropDown_TextUpdate(object sender, EventArgs e)
{
var company = (NMA0701R)companyDropDown.SelectedItem;
var items = priceCalculatorContext.GetCustomers(company.CompanyNumber, 0);
List<string> stringList = items.Select(i => i.ToString()).ToList();
string filter_param = customersDropDown.Text;
List<string> filteredItems = stringList.FindAll(x => x.ToLower().Contains(filter_param.ToLower()));
customersDropDown.DisplayMember = "FullCustomer";
customersDropDown.ValueMember = "CustomerNumber";
customersDropDown.DataSource = filteredItems;
if (String.IsNullOrWhiteSpace(filter_param))
{
customersDropDown.DataSource = items;
}
customersDropDown.DroppedDown = true;
Cursor.Current = Cursors.Default;
// this will ensure that the drop down is as long as the list
customersDropDown.IntegralHeight = true;
// remove automatically selected first item
customersDropDown.SelectedIndex = -1;
customersDropDown.Text = filter_param;
// set the position of the cursor
customersDropDown.SelectionStart = filter_param.Length;
customersDropDown.SelectionLength = 0;
}
我已使用此答案尝试让我的代码正常工作:https://stackoverflow.com/a/40990757/11707295 我希望能够进行包含搜索而不是 StartsWith。
【问题讨论】: