Reputation: 9
I'm working on a WPF project with VB.net, and for one specific part I need to display (part of) a MySQL table which is editable (at least some fields are).
Now I got this working by loading the data from the MySQL database into a DataTable, from which a DataGrid pulls all its values. One of the columns in this DataGrid is a Combobox with 4 default options, but I can't get it working that the selected value in this combobox is linked to the datatable (other fields are working fine by setting the binding to the name of the column in the datatable).'
This is the current XAML code for the ComboBox.
<DataGridTemplateColumn Header="Status" CellStyle="{StaticResource DataGridComboBox}">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Margin="2" SelectedValue="{Binding XPath=item_status}">
<ComboBoxItem Name="not_approved">Not Approved</ComboBoxItem>
<ComboBoxItem Name="on_hold">On Hold</ComboBoxItem>
<ComboBoxItem Name="approved">Approved</ComboBoxItem>
<ComboBoxItem Name="ad_hoc">Ad Hoc</ComboBoxItem>
</ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
I tried binding the values from the data grid to the combobox by setting the SelectedValue, but this isn't working.
Screenshot of the program here
If you look at the screenshot, you can see the combobox in the second column (Status). All the other field come, as said, directly from the DataTable. In the DataTable, the value in this column for the first row is Not Approved, and now I selected it manually, but normally this should load automatically.
Upvotes: 0
Views: 474
Reputation: 752
You can use the DataGridComboBoxColumn
and set the ItemsSource property to a collection of strings ('Not Approved', 'On Hold' etc)
Upvotes: 0