I currently have a C#
WPF
.NET 4.5
application. I am using a DataGrid
to show items from the project's database. I am able to populate everything in the DataGrid
except for the DataGridComboBoxColumn
. First, i would just like to get it to display data. In the future, I would like the combobox to display on the first line the current value in the database, but have the ComboBox contain set values, to limit what users can enter. SO it would be like list item1 = current value, list item2 = pounds, list item3 = ounces, etc. The Table has 3 columns I am working with, InventoryName, Qty, and Type. Type should be the ComboBox
Here is my Code
private AuroraDataEntities auroraDataEntities;
public ViewCup()
{
InitializeComponent();
}
private void Window_Loaded(object sender, RoutedEventArgs e)
{
LoadData();
}
private void LoadData()
{
auroraDataEntities = new AuroraDataEntities();
dgInv.DataContext = auroraDataEntities.Inventories;
}
void EditComplete(object sender, SelectedCellsChangedEventArgs e)
{
auroraDataEntities.SaveChanges();
}
private void Window_Unloaded(object sender, RoutedEventArgs e)
{
auroraDataEntities.SaveChanges();
}
}
And here is my XAML
<DataGrid x:Name="dgInv" HorizontalAlignment="Center" Height="134" Margin="-10,96,10,0" VerticalAlignment="Top" Width="Auto"
IsSynchronizedWithCurrentItem="True"
ItemsSource="{Binding}"
AutoGenerateColumns="False"
GridLinesVisibility="None"
SelectedCellsChanged="EditComplete">
<DataGrid.Columns>
<DataGridTextColumn Width="200" Header="InventoryName" Binding="{Binding InventoryName}" />
<DataGridTextColumn Width="50" Header="Qty" Binding="{Binding Qty}" />
<DataGridComboBoxColumn x:Name="cbType"
Width="50"
Header="Type"
ItemsSource="{Binding Path=Type, Mode=TwoWay}"
DisplayMemberPath="Type"
SelectedValueBinding="{Binding Type}" >
</DataGridComboBoxColumn>
</DataGrid.Columns>
</DataGrid>