show some static values in wpf datagrid combobox column

VNarasimhaM picture VNarasimhaM · Jan 11, 2010 · Viewed 9k times · Source

I am trying to use a DataGrid whose first column is a ComboxBox. This ComboxBox has a hardcoded static values, possible values are: Employee, Contractor, Supplier

How can I show some static values in the DataGrid without binding to a DataSource. I am new to WPF so more detailed explanation would help.

Answer

Aran Mulholland picture Aran Mulholland · Jan 11, 2010

if you mean the wpf toolkit datagrid, you could do it like so:

        <dg:DataGridComboBoxColumn 
           Header="String Column" 
           SelectedItemBinding="{Binding Path=RoleProperty}">
           <dg:DataGridComboBoxColumn.ItemsSource>
              <CompositeCollection>
                 <system:String>Employee</system:String>
                 <system:String>Contractor</system:String>
                 <system:String>Supplier</system:String>
              </CompositeCollection>
           </dg:DataGridComboBoxColumn.ItemsSource>
        </dg:DataGridComboBoxColumn>

in this the items displayed have a property called RoleProperty. you would also need an xnl namespace defintion at the top of your xaml (with the rest of them like:

   xmlns:system="clr-namespace:System;assembly=mscorlib"

to let you include the system namespace. (to get access to the Strings)