简体   繁体   English

如何通过更改文本更改组合框中的下拉项?

[英]How to change dropdown items in combobox with change of text?

I am working on POS using EPF C#. 我正在使用EPF C#在POS上工作。 To add saleline items I want to use combobox and want to change selection for its dropdown with the change of text in combobox to search? 要添加销售订单项,我想使用组合框,并希望通过下拉菜单中的文本更改来更改其下拉菜单的选择范围以进行搜索? How can I change combox list items with Textchanged property or any other way? 如何使用Textchanged属性或其他任何方式更改combox列表项? And Can I also use datagrid columns or datagrid for this purpose? 我是否也可以为此目的使用datagrid列或datagrid?

After reading your comments it appears you want a textbox that is able to filter a list of items. 阅读评论后,您似乎需要一个能够过滤项目列表的文本框。 My suggestion would be to subscribe to the textboxes "textchanged" event. 我的建议是订阅文本框“ textchanged”事件。

textbox.TextChanged += Textbox_TextChanged;

Then do the filtering in the method that you used to subscribe to the event with 然后使用您用来订阅事件的方法进行过滤

private void Textbox_TextChanged(object sender, TextChangedEventArgs e)
{
    //do list sorting here ex.)
    List<string> FilteredResults = SomeList<string>.where(i => i.Contains(textbox.text)).ToList();
}

This will get you a filtered list of items (strings in this case) that you can then display in the ComboBox. 这将为您提供过滤后的项目列表(在这种情况下为字符串),然后可以将其显示在ComboBox中。

Note: The MVVM design pattern makes this extremely simple and clean to pull off. 注意:MVVM设计模式使其极其简单和干净。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM