ValueChanging事件是表格控件中经常使用到的事件,当单元格值发生改变时该事件将会被触发,通过该事件开发人员可以进行相应的操作,如数据验证、提示、更新等,这篇文章主要是讲
Xceed Grid For .NET表格控件中ValueChanging事件是如何使用的,具体可以参考下面的代码:
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 );