WPF Datagrid combobox issue

Perry J 0 Reputation points
2025-04-20T16:41:45.72+00:00

Hi All,

I have a WPF application in which I have a datagrid control which is used to display employee records. The last row of this datagrid is used to add new record on pressing “Enter” Key.

<DataGrid Grid.Row="2" Name="dtGrdEmployee" HorizontalAlignment="Right" AutoGenerateColumns="False" ItemsSource="{Binding Path= ListEmployee}" CanUserDeleteRows="False" MinHeight="50" Margin="10,10,5,5" Width="500" HorizontalGridLinesBrush="LightGray" VerticalGridLinesBrush="LightGray" Loaded="DataGrid_Loaded" CellEditEnding=" dtGrdEmployee _CellEditEnding" PreviewKeyDown="DataGrid_PreviewKeyDown">

              <DataGrid.RowValidationRules>

                  <local:DataRowValidation ValidationStep="UpdatedValue"></local:DataRowValidation>

              </DataGrid.RowValidationRules>

              <DataGrid.Columns>

                  <DataGridComboBoxColumn x:Name="cmbEmployee" Header="Employee Name" DisplayMemberPath="Name" SelectedValuePath="ID" SelectedValueBinding="{Binding Path= EmployeeID, Mode=TwoWay, UpdateSourceTrigger=PropertyChanged}"></DataGridComboBoxColumn>

                  <DataGridTextColumn Header="Column 2" ElementStyle="{StaticResource CellTextRightAlign}" HeaderStyle="{StaticResource HeaderContentRightAlign}">

                      <DataGridTextColumn.Binding>

                          <Binding Path="Column2" Mode="TwoWay" StringFormat="{}{0:n2}">

                              <Binding.ValidationRules>

                                  <local:DataRowValidation ValidationStep="UpdatedValue"></local:DataRowValidation>

                              </Binding.ValidationRules>

                          </Binding>

                      </DataGridTextColumn.Binding>

                  </DataGridTextColumn>

                  <DataGridTextColumn IsReadOnly="True" Binding="{Binding Path= EmployeeID, Converter={StaticResource EmployeeConverter} }"></DataGridTextColumn>

                  <DataGridTextColumn Header="Column 4" IsReadOnly="True" ElementStyle="{StaticResource CellTextRightAlign}" HeaderStyle="{StaticResource HeaderContentRightAlign}">

                      <DataGridTextColumn.Binding>

                          <Binding Path="Column4" Mode="TwoWay" StringFormat="{}{0:n2}">

                              <Binding.ValidationRules>

                                  <local:DataRowValidation ValidationStep="UpdatedValue"></local:DataRowValidation>

                              </Binding.ValidationRules>

                          </Binding>

                      </DataGridTextColumn.Binding>

                  </DataGridTextColumn>

                  <DataGridTextColumn Header="Comments">

                      <DataGridTextColumn.Binding>

                          <Binding Path="Comments">

                              <Binding.ValidationRules>

                                  <local:DataRowValidation ValidationStep="UpdatedValue"></local:DataRowValidation>

                              </Binding.ValidationRules>

                          </Binding>

                      </DataGridTextColumn.Binding>

                  </DataGridTextColumn>

              </DataGrid.Columns>              </DataGrid>

Based on selection/value in first(combobox) column, it will check the EmployeeType column in SQL Server database table and if EmployeeType = 1 then “Column 2” will be editable with “Column 4” non-editable/readonly. If EmployeeType = 2 then “Column 4” will be editable with “Column 2” non-editable/readonly.

Please suggest how can I achieve the same ASAP.

Regards,

Perry

XAML
XAML
A language based on Extensible Markup Language (XML) that enables developers to specify a hierarchy of objects with a set of properties and logic.
848 questions
0 comments No comments
{count} votes

Your answer

Answers can be marked as Accepted Answers by the question author, which helps users to know the answer solved the author's problem.