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.
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)
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>
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With