Skip to content

This example explains about how to validate the text in edit mode of GridTextColumn in DataGrid(SfDataGrid).

Notifications You must be signed in to change notification settings

SyncfusionExamples/how-to-validate-the-text-in-edit-mode-of-grid-text-column-in-data-grid

Folders and files

NameName
Last commit message
Last commit date

Latest commit

 

History

11 Commits
 
 
 
 
 
 

Repository files navigation

How to validate the text in edit mode of GridTextColumn in DataGrid(SfDataGrid)?

About the sample

This example illustrates how to validate the text in edit mode of GridTextColumn in WPF DataGrid (SfDataGrid)?

WPF DataGrid (SfDataGrid) does not provide the direct support for validating the text in edit mode in GridTextBoxColumn. You can achieve this by customizing the GridCellTextBoxRenderer class. In this class you can get the old value and new value from KeyDown and KeyUp events.

public class GridCellTextBoxRendererExt : GridCellTextBoxRenderer
{
       string oldvalue = null;
       string newvalue = null;
        
       public override void OnInitializeEditElement(DataColumnBase dataColumn, TextBox uiElement, object dataContext)
       {
           base.OnInitializeEditElement(dataColumn, uiElement, dataContext);
           uiElement.KeyDown += UiElement_KeyDown;
           uiElement.KeyUp += UiElement_KeyUp;
       }

       private void UiElement_KeyUp(object sender, System.Windows.Input.KeyEventArgs e)
       {
           TextBox textBox = (e.OriginalSource as TextBox);
           newvalue = textBox.Text;
           Console.WriteLine("NewValue: " + newvalue + "\n\noldvalue: " + oldvalue);
           if (newvalue == "Sample")
           {
               textBox.Text = oldvalue;
               textBox.SelectionStart = textBox.Text.Length;
           }
       }

       private void UiElement_KeyDown(object sender, System.Windows.Input.KeyEventArgs e)
       {
           oldvalue = (e.OriginalSource as TextBox).Text;
       }
} 

KB article - How to validate the text in edit mode of GridTextColumn in DataGrid(SfDataGrid)?

Requirements to run the demo

Visual Studio 2015 and above versions

About

This example explains about how to validate the text in edit mode of GridTextColumn in DataGrid(SfDataGrid).

Topics

Resources

Stars

Watchers

Forks

Releases

No releases published

Packages

No packages published

Languages