您的位置:首页 > 其它

2.DataGridView 几个基本操作

2015-08-02 13:00 225 查看
DataGridView的几个基本操作:

1、获得某个(指定的)单元格的值:

dataGridView1.Row[i].Cells[j].Value;

2、获得选中的总行数:

dataGridView1.SelectedRows.Count;

3、获得当前选中行的索引:

dataGridView1.CurrentRow.Index;

4、获得当前选中单元格的值:

dataGridView1.CurrentCell.Value;

5、取选中行的数据

string[] str = new
string[dataGridView.Rows.Count];

for(int i;i

{

if(dataGridView1.Rows[i].Selected == true)

{

str[i] =
dataGridView1.Rows[i].Cells[1].Value.ToString();

}

}

7、获取选中行的某个数据

int a = dataGridView1.SelectedRows.Index;

dataGridView1.Rows[a].Cells["你想要的某一列的索引,想要几就写几"].Value;
内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: