【问题标题】:Filtering a combobox with a textbox使用文本框过滤组合框
【发布时间】:2016-04-05 05:56:44
【问题描述】:

正如标题所示,我想根据文本框中的内容过滤组合框中的值。组合框从列表中获取值。我已经尝试过AutoCompleteModeAutoCompleteSource,但是当我使用它们时它不允许我向组合框添加任何值。组合框包含以下类的列表的值。

class Groep
{
    //Fields
    private string naamGroep;


    //Properties
    public string NaamGroep
    {
        get { return this.naamGroep; }
        set { naamGroep = NaamGroep; }
    }



    //Constructor
    public Groep(string naam)
    {
        this.naamGroep = naam;

    }

这是列表:

List<Groep> Groepen = new List<Groep>();

我有两个文本框。一个用于将项目添加到列表中,另一个用于过滤组合框。

【问题讨论】:

    标签: c# filter combobox textbox


    【解决方案1】:

    使用foreach 循环来实现

    private void Button1_Click(object sender, EventArgs e)
    {
        ComboBox1.Items.Clear();
        foreach (Groep g in Groepen.Where(g => g.NaamGroep.Contains(TextBox1.Text)))
            ComboBox1.Items.Add(g.NaamGroep);
    }
    

    【讨论】:

      猜你喜欢
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 1970-01-01
      • 2018-05-12
      • 2022-07-06
      • 2021-10-02
      • 1970-01-01
      相关资源
      最近更新 更多