The ValueChanging event is raised every time a cell's value is being changed. It provides notification that the cell's value is changing and provides the opportunity to cancel any modifications.
Basic steps - C#
To subscribe to the ValueChanging event, the following steps must be performed:
-
Obtain a reference to a Cell object.
-
Subscribe to the ValueChanging event of the Cell object using the ValueChangingEventHandler delegate class
-
Create a new method that will handle the events that are raised.
-
Place the desired code in the newly created event handler.
Basic steps - VB.NET
To subscribe to the ValueChanging event, the following steps must be performed:
-
Obtain a reference to a Cell object.
-
Subscribe to the ValueChanging event of the Cell object using the AddHandler/AddressOf keywords.
-
Create a new method that will handle the events that are raised.
-
Place the desired code in the newly created event handler.
Demonstration
This example assumes that you are in a Windows application.
VB.NET |
Copy Code |
Imports Xceed.Grid
Dim cell As Cell For Each cell in gridControl1.DataRowTemplate.Cells AddHandler cell.ValueChanging, AddressOf Me.cell_ValueChanging Next cell
' This method will handle the ValueChanging events that are raised. Private Sub cell_ValueChanging( ByVal sender As Object, ByVal e As ValueChangingEventArgs ) Try If( e.NewValue is String ) And ( CType( e.NewValue, String ) = "Hello" ) Then e.Cancel = True End If Catch exception As Exception MessageBox.Show( exception.ToString() ) End Try End Sub
' If you no longer wish to handle the ValueChanging events that are raised, ' you can unsubscribe from the event notification by doing the following: RemoveHandler cell.ValueChanging, AddressOf Me.cell_ValueChanging
|
C# |
Copy Code |
using Xceed.Grid;
foreach( Cell cell in grid.DataRowTemplate.Cells ) { cell.ValueChanging += new ValueChangingEventHandler( this.cell_ValueChanging ); }
// This method will handle the ValueChanging events that are raised. private void cell_ValueChanging( object sender, ValueChangingEventArgs e ) { try { if( ( e.NewValue is string ) && ( ( string )e.NewValue == "Hello" ) ) { e.Cancel = true; } } catch( Exception exception ) { MessageBox.Show( exception.ToString() ); } }
// If you no longer wish to handle the ValueChanging events that are raised, // you can unsubscribe from the event notification by doing the following: cell.ValueChanging -= new ValueChangingEventHandler( this.cell_ValueChanging );
|