C#中对DatagridView部分常用操作
0(最基本的技巧)、获取某列中的某行(某单元格)中的内容
this.currentposition = this.dataGridView1.BindingContext
[this.dataGridView1.DataSource, this.dataGridView1.DataMember].Position;
bookContent = this.database.dataSet.Tables[0].Rows
[this.currentposition][21].ToString().Trim();
MessageBox.Show(bookContent);
1、自定义列
//定义列宽
this.dataGridView1.Columns[0].Width = 80;
this.dataGridView1.Columns[1].Width = 80;
this.dataGridView1.Columns[2].Width = 180;
this.dataGridView1.Columns[3].Width = 120;
this.dataGridView1.Columns[4].Width = 120;
Customize Cells and Columns in the Windows Forms
DataGridView Control by Extending TheirBehavior and
AppearanceHost Controls in Windows Forms DataGridView Cells
继承 DataGridViewTextBoxCell 类生成新的Cell类,然后再继承 DataGridViewColumn 生成新的Column类,并指定
CellTemplate为新的Cell类。新生成的Column便可以增加到DataGridView中去。
2、自动适应列宽
Programmatically Resize Cells to Fit Content in
the Windows Forms DataGridView ControlSamples:
相关新闻>>
- 发表评论
-
- 最新评论 更多>>