Reputation: 1
I am trying to bind data from a database to a datagrid in WPF using Caliburn.Micro. Caliburn works great with standard text columns but when I try binding the data to a Template Column the data doesnt show up on the screen. For example, in the Material Item column the items show up in the view just by a simple binding. But when I try using a template column with a combobox the same thing doesnt happen. The goal here is to pull data from a database into the view using a Bindablecollection ... Then have a dropdown menu to choose from Material Status, Ordered, Not in Stock, In Stock. Its a really simple Idea to have the past chosen Status (e.g. Not in Stock) changed (e.g. In Stock) and its in many applications. Here is the code and a picture of whats going on.
<DataGrid AutoGenerateColumns="False"
ScrollViewer.CanContentScroll="True"
ScrollViewer.VerticalScrollBarVisibility="Auto"
ScrollViewer.HorizontalScrollBarVisibility="Auto"
CanUserAddRows="False"
x:Name="ProjectMaterialList"
SelectedItem="{Binding SelectedMaterialItem}"
Margin="10,10,10.333,10">
<DataGrid.Columns>
<DataGridTextColumn Header="MaterialId"
Binding="{Binding MaterialId}"
CanUserResize="False"
Visibility="Hidden" />
<DataGridTextColumn Header="Project"
Binding="{Binding ProjectName}"
CanUserResize="False"
Width="15*" />
<DataGridTextColumn Header="Type"
Width="7*"
Binding="{Binding MaterialType}"
CanUserResize="False" />
<DataGridTextColumn Header="Quantity"
CanUserResize="False"
Binding="{Binding MaterialQuantity}"
Width="5*" />
<DataGridTextColumn Header="Unit"
Binding="{Binding MaterialMeasureType}"
CanUserResize="False"
Width="5*" />
<DataGridTextColumn Header="Measure"
Binding="{Binding MaterialMeasure}"
CanUserResize="False"
Width="5*" />
<DataGridTextColumn Header="Item"
Binding="{Binding MaterialItem}"
CanUserResize="False"
Width="15*" />
<DataGridTemplateColumn Header="Status"
CanUserResize="False"
Width="11*"
x:Name="MaterialStatus">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<TextBox Text="{Binding MaterialModel.MaterialStatus }" />
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox ItemsSource="{Binding Path=OrderStatuses }"
SelectedItem="MaterialStatus" />
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
</DataGrid.Columns>
</DataGrid>
What Happens What I Want to happend
Upvotes: 0
Views: 62
Reputation: 784
you didnt specify an item source for your datagrid ? item source should be bound to your observable collection something like:
ItemsSource="{Binding ListOfMaterial}"
Upvotes: 0