你的位置:首页 > 软件开发 > ASP.net > Winform datagridview 基础

Winform datagridview 基础

发布时间:2016-09-10 11:00:05
======================================================================================== ==重点需要掌握AutoSizeColumnsMode 设置为File ...

======================================================================================== ==

重点需要掌握

AutoSizeColumnsMode   设置为File    列填充效果

RowHeadersVisible   设置false    第一列不显示

SelectionModel    设置FullRowSelect  行被选中

AllowUserToResizeRows  设置False    Dataget='_blank'>GridView是否可以调整行的大小

AutoGenerateColumns  设置False   设置不自动生成列,此属性在属性面板中没有

ClearSelection();     取消加载默认选中第一行

DataGridView的值绑定到文本框 实现方式:在CellClick事件中实现如下代码 方法1  

int rowIndex=this.dataGridView控件.CurrentCell.RowIndex;

this.文本框名.Text = this.dataGridView控件[0,rowIndex].Value.ToString(); t

his.文本框名.Text = this.dataGridView控件[1,rowIndex].Value.ToString(); ========================================================================================

注意:下列代码中的i是定义成全局变量

///[第一行] 代码如下:

//获取选中行的索引值  

this.i = this.dataGridView1.SelectedCells[0].RowIndex;  

if (this.i <= 0)   {       MessageBox.Show("已经是第一行了!",                                   "提示",                     MessageBoxButtons.OK,                     MessageBoxIcon.Information);   }  

else   {       this.dataGridView1.Rows[i].Selected = false;       this.dataGridView1.Rows[0].Selected = true;   }

///[下一行] 代码如下:

//获取选中行的索引值

this.i = this.dataGridView1.SelectedCells[0].RowIndex;

if (this.i < this.dataGridView1.RowCount - 1) {     this.dataGridView1.Rows[i].Selected = false;     this.dataGridView1.Rows[++i].Selected = true; }

else {     MessageBox.Show("已经是最后一行了!",                                   "提示",                     MessageBoxButtons.OK,               MessageBoxIcon.Information); }

///[上一行] 代码如下:

//获取选中行的索引值   

this.i = this.dataGridView1.SelectedCells[0].RowIndex;  

if (this.i <= 0)   {       MessageBox.Show("已经是第一行了!",                                   "提示",                     MessageBoxButtons.OK,                     MessageBoxIcon.Information);   }  

else   {       this.dataGridView1.Rows[i].Selected = false;       this.dataGridView1.Rows[--i].Selected = true;   }

///[最后行] 代码如下:

//获取选中行的索引值    

this.i = this.dataGridView1.SelectedCells[0].RowIndex;  

if (this.i < this.dataGridView1.RowCount - 1)   {       this.dataGridView1.Rows[i].Selected = false;       this.dataGridView1.Rows[this.dataGridView1.RowCount - 1].Selected = true;   }  

else   {       MessageBox.Show("已经是最后一行了!", "提示", MessageBoxButtons.OK, MessageBoxIcon.Information);   }  


原标题:Winform datagridview 基础

关键词:GridView

*特别声明:以上内容来自于网络收集,著作权属原作者所有,如有侵权,请联系我们: admin#shaoqun.com (#换成@)。