Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Bind the datatable with ComboBox in WPF

Data is not Displaying in the Combo Box

DataTable dt = new DataTable();
dt.Columns.Add("Code");
dt.Columns.Add("Name");
dt.Rows.Add("c1", "n1");
dt.Rows.Add("c2", "n2");
myCombo.ItemsSource = ((IListSource)dt).GetList();
myCombo.DisplayMemberPath = "Code";
myCombo.SelectedValuePath = "Name";
like image 340
Manoj S Pant Avatar asked May 20 '26 06:05

Manoj S Pant


1 Answers

instead of this line

myCombo.ItemsSource = ((IListSource)dt).GetList();

try to use this one

myCombo.ItemsSource = dt.DefaultView;
like image 137
Kishore Kumar Avatar answered May 22 '26 02:05

Kishore Kumar



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!