all groups > dotnet windows forms > may 2007 >
You're in the

dotnet windows forms

group:

WPF HOW TO: Insert a ComboxBoxItem after databinding?


WPF HOW TO: Insert a ComboxBoxItem after databinding? ER
5/7/2007 9:20:31 PM
dotnet windows forms: 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

Re: WPF HOW TO: Insert a ComboxBoxItem after databinding? ER
5/8/2007 6:23:20 PM
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;


[quoted text, click to view]

AddThis Social Bookmark Button