tags:

views:

427

answers:

2

I am trying to use a datagrid whose first column is a comboxbox. This combobox 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.

+1  A: 

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>
cory.m.smith
+1  A: 

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)

Aran Mulholland
`<x:Array>` would be significantly more efficient than `<CompositeCollection>`, and more readable too - most people don't know what a `CompositeCollection` is, let alone that it can be used this way. An array is a much cleaner choice in my opinion.
Ray Burns
excellent idea ray. i was coding too fast using intellisense and composite collection came up first.
Aran Mulholland
gave it a go (and in the two minutes or so i tried) and couldnt get array instantiated in xaml, said something about no public constructor
Aran Mulholland