Articles in this section

How to change column values based on another column in WPF TreeGrid?

In WPF TreeGrid (SfTreeGrid), it is possible to change the value in one column based on the value edited in another column by utilizing the CurrentCellValidated event. This event allows you to access the current cell’s row data and update the necessary column value based on specific conditions.

Step 1: Subscribe to the CurrentCellValidated Event: In the constructor of your main window, subscribe to the CurrentCellValidated event of the TreeGrid.

public MainWindow()
{
   InitializeComponent();
   this.treeGrid.CurrentCellValidated += TreeGrid_CurrentCellValidated;
} 

Step 2: Handle the Event: In the event handler, check if the edited column is one of the columns you want to monitor (e.g., “BasicPay” or “Reduction”). If so, retrieve the relevant data and update the target column accordingly.

private void TreeGrid_CurrentCellValidated(object sender, TreeGridCurrentCellValidatedEventArgs e)
{
    if (e.RowData != null && (e.Column.MappingName == "BasicPay" || e.Column.MappingName == "Reduction"))
    {
        var reduction = (e.RowData as EmployeeInfo).Reduction;
        var basicPay = (e.RowData as EmployeeInfo).BasicPay;
        (e.RowData as EmployeeInfo).Salary = basicPay - reduction;
    }                        
} 

The above implementation will automatically update the Salary column whenever the BasicPay or Reduction columns are modified.

c2zBvcs8AX.gif

Take a moment to peruse the WPF TreeGrid - Data Validation, to learn more about the Data Validation with examples.

View sample in GitHub

Conclusion

​I hope you enjoyed learning on how to change column values based on another column in TreeGrid.

You can refer to our WPF TreeGrid feature tour page to know about its other groundbreaking feature representations and documentation, and how to quickly get started for configuration specifications.

For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.

If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!

Did you find this information helpful?
Yes
No
Help us improve this page
Please provide feedback or comments
Comments (0)
Access denied
Access denied