c# combobox filtering one combobox based on the value of another combobox

zleug 61 Reputation points
2020-03-25T17:07:46.91+00:00

Hi All.
I created form with two ComboBox. And I would like that selection in ComboBox1 filter ComboBox2.
Here is my code to populate ComboBox1:

public partial class Window1 : Window

{

MyDataSet ds = new MyDataSet();

MyDataSetTableAdapters.Table1TableAdapter tb1TableAdapter = new MyDataSetTableAdapters.Table1TableAdapter();

MyDataSetTableAdapters.Table2TableAdapter tb2TableAdapter = new MyDataSetTableAdapters.Table2TableAdapter();

BindingListCollectionView cvCombo1;

BindingListCollectionView cvCombo2;

public Window1()

{

InitializeComponent();

}

private void Window_Loaded(object sender, RoutedEventArgs e)

{

PopulateCombo1();

}

public void PopulateCombo1()

{

tb1TableAdapter.Fill(ds.Table1);

cvCombo1 = ((BindingListCollectionView)(CollectionViewSource.GetDefaultView(ds.Table1)));

CollectionViewSource cb1Source = FindResource("cvCombo1") as CollectionViewSource;

cb1Source.Source = ds.Table1;

}

public void PopulateCombo2()

{

tb2TableAdapter.Fill(ds.Table2);

cvCombo2 = ((BindingListCollectionView)(CollectionViewSource.GetDefaultView(ds.Table2)));

CollectionViewSource cb2Source = FindResource("cvCombo2") as CollectionViewSource;

cb2Source.Source = ds.Table2;

}

}

How to filter ComboBox2?

Thanks.

Not Monitored
Not Monitored
Tag not monitored by Microsoft.
35,815 questions
0 comments No comments
{count} votes

1 answer

Sort by: Most helpful
  1. Dave Patrick 426K Reputation points MVP
    2020-06-01T01:18:14.04+00:00

    Windows Forms is not currently supported here on QnA. I'd try asking for help in dedicated forums here.

    https://social.msdn.microsoft.com/Forums/sqlserver/en-US/home?category=windowsforms

    --please don't forget to Accept as answer if the reply is helpful--


    Regards, Dave Patrick ....
    Microsoft Certified Professional
    Microsoft MVP [Windows Server] Datacenter Management

    Disclaimer: This posting is provided "AS IS" with no warranties or guarantees, and confers no rights.

    0 comments No comments