——此文章摘自《C#高级编程(第
版)》定价
元 特价
元 购买
{
private SystemWindowsFormsButton retrieveButton;
private SystemWindowsFormsDataGrid dataGrid;
public CustomDataGridTableStyle()
{
thisAutoScaleBaseSize = new SystemDrawingSize( );
thisClientSize = new SystemDrawingSize( );
thisText = _CustomDataGridTableStyle;
thisdataGrid = new SystemWindowsFormsDataGrid();
dataGridBeginInit();
dataGridLocation = new SystemDrawingPoint( );
dataGridSize = new SystemDrawingSize( );
dataGridTabIndex = ;
dataGridAnchor = AnchorStylesBottom | AnchorStylesTop |
AnchorStylesLeft | AnchorStylesRight;
thisControlsAdd(thisdataGrid);
dataGridEndInit();
thisretrieveButton = new SystemWindowsFormsButton();
retrieveButtonLocation = new SystemDrawingPoint( );
retrieveButtonSize = new SystemDrawingSize( );
retrieveButtonTabIndex = ;
retrieveButtonAnchor = AnchorStylesBottom | AnchorStylesRight;
retrieveButtonText = Retrieve;
retrieveButtonClick += new
SystemEventHandler(thisretrieveButton_Click);
thisControlsAdd(thisretrieveButton);
}
protected void retrieveButton_Click(object sender SystemEventArgs e)
{
retrieveButtonEnabled = false;
这些代码生成将要使用的DataSet接着创建了本例中要使用的DataGridTableStyle最后把DataGrid绑定到DataSet上CreateDataSet函数并不是新东西它可以从Customers表中选择出所有的行
DataSet ds = CreateDataSet();
CreateStyles(dataGrid);
dataGridSetDataBinding(ds Customers);
}
CreateStyles()方法比较有趣前几行代码创建新的DataGridTableStyle对象并且设置了它的MappingName属性这个属性在DataGrid显示一个给定的DataTable时使用DataGrid可以用交替变化的颜色显示数据行这段代码还每隔一行定义数据行的颜色(结果如图所示)
[] [] []