I have a DataGrid to insert data into Sql Server table. Inside of DataGrid I have ComboBox to pick the data from a codebook (this is the table from the same database) and insert this data into table I bound to DataGrid. This is the XAML:
<DataGrid Name="dgrStavke" AutoGenerateColumns="False" Height="160" Width="600" HorizontalAlignment="Left" Margin="5" Grid.Row="7" Grid.ColumnSpan="4">
<DataGrid.Columns>
<DataGridTemplateColumn Header="Artikl ID">
<DataGridTemplateColumn.CellTemplate>
<DataTemplate>
<ComboBox Name="cmbArticle" Width="120" ></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Article Name" Width="150"></DataGridTextColumn>
<DataGridTemplateColumn Header="Usluga ID">
<DataGridTemplateColumn.CellEditingTemplate>
<DataTemplate>
<ComboBox Name="cmbService" Width="120"></ComboBox>
</DataTemplate>
</DataGridTemplateColumn.CellEditingTemplate>
</DataGridTemplateColumn>
<DataGridTextColumn Header="Service Name" Width="150"></DataGridTextColumn>
</DataGrid.Columns>
</DataGrid>
When I choose article id in combobox article, the very next DataGridTextColumn should display name of this article. The same is for service. It’s possible to insert few articles and services and that’s the reason I use Datagrid.
How can I do this?
Thanks.
I guess the below sample would help you to achieve your goal
In XAML below code used,
In C# below code used,
In the MainWindow the below code could helps to binding the grid.
Please Comment If you have any clarification needed. I’ll help you