Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

show some static values in wpf datagrid combobox column

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.

like image 736
VNarasimhaM Avatar asked Dec 05 '22 03:12

VNarasimhaM


2 Answers

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)

like image 56
Aran Mulholland Avatar answered Dec 11 '22 07:12

Aran Mulholland


You can just use a standard ComboBox with your static values as ComboBoxItems like so:

<ComboBox>
  <ComboBoxItem>Employee</ComboBoxItem>
  <ComboBoxItem>Contractor</ComboBoxItem>
  <ComboBoxItem>Supplier</ComboBoxItem>
</ComboBox>
like image 33
Smixx Avatar answered Dec 11 '22 07:12

Smixx