WEB开发网
开发学院软件开发C语言 C#中对DatagridView的部分常用操作 阅读

C#中对DatagridView的部分常用操作

 2009-05-21 08:27:46 来源:WEB开发网   
核心提示: 7、格式化显示内容:Format Data in the Windows Forms DataGridView ControlSamples:this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format

7、格式化显示内容:

Format Data in the Windows Forms DataGridView Control

Samples:

this.dataGridView1.Columns["UnitPrice"].DefaultCellStyle.Format = "c";
this.dataGridView1.Columns["ShipDate"].DefaultCellStyle.Format = "d";
this.dataGridView1.DefaultCellStyle.NullValue = "no entry";
this.dataGridView1.DefaultCellStyle.WrapMode = DataGridViewWrapMode.Wrap;
this.dataGridView1.Columns["CustomerName"].DefaultCellStyle.Alignment =
DataGridViewContentAlignment.MiddleRight;

8、在拖动列的滚动条时可以将指定的列冻结

Freeze Columns in the Windows Forms DataGridView Control

Samples:将指定列及以前的列固定不动

this.dataGridView1.Columns["AddToCartButton"].Frozen = true;

9、获取选择的单元格,行,列

Get the Selected Cells, Rows, and Columns in the Windows Forms DataGridView Control
Samples:

见msdn。

10、显示录入时出现的错误信息

Handle Errors that Occur During Data Entry in the Windows Forms DataGridView Control
Samples:
private void dataGridView1_DataError(object sender,
DataGridViewDataErrorEventArgs e)
{
// If the data source raises an exception when a cell value is
// commited, display an error message.
if (e.Exception != null &&
e.Context == DataGridViewDataErrorContext.Commit)
{
MessageBox.Show("CustomerID value must be unique.");
}
}

上一页  1 2 3 4  下一页

Tags:DatagridView 部分 常用

编辑录入:爽爽 [复制链接] [打 印]
赞助商链接