Xceed Grid For .NET表格控件单元格值改变事件的应用

作者:控件中国网   出处:控件中国网   2015-10-28 09:00:30   阅读:3

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 );
Copyright© 2006-2015 ComponentCN.com all rights reserved.重庆磐岩科技有限公司(控件中国网) 版权所有 渝ICP备12000264号 法律顾问:元炳律师事务所
客服软件
live chat