WPF HOW TO: Insert a ComboxBoxItem after databinding?

E

ER

Hi All

I have a ComboBox that is bound to a DataTable returned from a Business
Logic Component.

How to I insert a new ComboBoxItem after binding.

My Code so Far:
StockItemDepartmentBLLC s = new StockItemDepartmentBLLC();

cmbDepartment.DataContext = s.GetDepartmentsForDDL(); //returns a DataTable


ComboBoxItem item = new ComboBoxItem();

item.Content = "All Departments";

cmbDepartment.Items.Insert(0, item);

Any pointers greatly appreciated.

Evil R
 
E

ER

Ended up recursing the DataRows:

SupplierBLLC s = new SupplierBLLC();

DataTable dt = s.GetSuppliersForDDL();

ComboBoxItem item;

foreach (DataRow dr in dt.Rows)

{

item = new ComboBoxItem();

item.Content = dr["Name"];

item.Tag = Convert.ToInt32(dr["SupplierID"]);

cmbSupplier.Items.Add(item);

}

item = new ComboBoxItem();

item.Content = "All";

item.Tag = -1;

cmbSupplier.Items.Insert(0, item);

cmbSupplier.SelectedIndex = 0;
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top