Change combo box item list depending on the Textbox Text

后端 未结 3 858
广开言路
广开言路 2021-01-27 16:29

I have two columns in my grid:

Name(Textbox) ---- ParentList(combobox).

A ----------------------- It sh

3条回答
  •  醉梦人生
    2021-01-27 17:15

    That's easy to achieve if you slightly adapt your data type class... I've had to guess at the type of your ParentList because you didn't show it:

    private List allItems = GetAllItems();
    
    public ObservableCollection ParentList
    {
        get { return parentList; }
        set
        {
            parentList = value;
            NotifyPropertyChanged("ParentList");
        }
    }
    
    public string Name
    {
        get { return name; }
        set
        {
            name = value;
            NotifyPropertyChanged("Name");
            ParentList = new ObservableCollection(allItems.Where(i => IsFiltered(i)));
        }
    }
    
    private bool IsFiltered(string item)
    {
        // implement your filter condition here
        return item.StartsWith("A");
    }
    

    So the basic idea is that you hold a private collection of all the possible values... this remains unchanged. Each time the Name property is changed, we create a new ParentList dependant on some filtering condition in the IsFiltered method.

提交回复
热议问题