winform datagridview如何获取索引 分类: DataGridView 2014-04-11 13:42 216人阅读 评论(0) 收藏



datagridview.CurrentCell.RowIndex;            是当前活动的单元格的行的索引

datagridview.SelectedRows  ;                        是选中行的集合
datagridview.SelectedColumns ;                   是选中列的集合
datagridview.SelectedCells  ;                        是选中单元格的集合 

DataGridView1.CurrentRow.Index;                获得包含当前单元格的行



举例:

DataSet ds=new DataSet();

ds=DataAccess.GetDataSet(sql,falase,null);//数据连接

int id;

id=Convert.ToInt32(ds.Tables[0].CurrentRow.cells["ID"].ToString());

//这样就可以获取DataGridView中当前行的ID

版权声明:本文为博主原创文章,未经博主允许不得转载。

posted @ 2014-04-11 13:42  Jackerson  阅读(137)  评论(0编辑  收藏  举报