Xceed Grid For .NET怎么使表格绑定和非绑定模式同时使用

作者:控件中国网   出处:控件中国网   2015-09-01 10:06:56   阅读:4

Xceed Grid For .NET是一款常用的表格类控件,功能强大且使用简单,在使用表格时经常需要对表格部分列进行数据绑定,从数据源获取数据,而一部分列则需要手动添加或者录入,那么怎么才能使表格同时具备绑定列和非绑定列呢?Xceed Grid For .NET控件为开发人员提供了简便的方法,轻松可实现该功能,具体可以参考下面的代码:

using Xceed.Grid;

// Add the first column to the grid. This column will contain the day
// of the week displayed as text.

Column column1 = new Column( "Day", typeof( string ) );
gridControl1.Columns.Add( column1 );

//  Create the second column that will display the hour.
Column column2 = new Column( "Time", typeof( DateTime ) );

// Since we only want the time, we will set the column's
// FormatSpecifier to a LongTimePattern

column2.FormatSpecifier = "T";

// Add the second column to the grid.
gridControl1.Columns.Add( column2 );

// Subscribe to the AddingDataRow event
gridControl1.AddingDataRow += new AddingDataRowEventHandler( this.grid_AddingDataRow );

// Bind the grid to a data source. For the purposes of this example
// we will assume that there is a dataset named dataSet11 that
// contains a table called Orders.

gridControl1.DataSource = dataSet11;
gridControl1.DataMember = "Orders";

// We could have also used the SetDataBinding method.
//gridControl1.SetDataBinding( dataSet11, "Orders" ); 

// This procedure will handle the AddingDataRow event and will
// provide the data for our 2 unbound columns.

private void grid_AddingDataRow( object sender, AddingDataRowEventArgs e )
{
   try
   {
      e.DataRow.Cells[ "Day" ].Value = DateTime.Today.Date.DayOfWeek.ToString();
      e.DataRow.Cells[ "Time" ].Value = DateTime.Now;
   }
   catch( Exception exception )
   {
      MessageBox.Show( exception.ToString() );
   }
}

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