c#winfrom datagridview 选中项

伤逝的离别 2014-06-25 10:06:33
怎么把 dataGridView 选中项 设置为索引的值呢、
就是说,dataGridView 的默认项是第一列第一行,然后我想让他默认为第一列第2行。。

就是重新绑定数据的时候,那个三角形箭头 是跳到2,而不是1
求简单的代码、 新手T-T

...全文
102 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
伤逝的离别 2014-06-25
  • 打赏
  • 举报
回复
引用 4 楼 duanzi_peng 的回复:
[quote=引用 2 楼 u013531238 的回复:] [quote=引用 1 楼 wangnaisheng 的回复:]


int rowIndex=3;//指定行号           

this.dgvInGoodsInfo.Rows[rowIndex].Selected = true;
this.dgvInGoodsInfo.CurrentCell = this.dgvInGoodsInfo.Rows[rowIndex].Cells[0];
我隐藏了第一列,就不能指定了、、要怎么做呢?[/quote] Cells[0] -> Cells[1][/quote] 感谢、感激不尽
exception92 2014-06-25
  • 打赏
  • 举报
回复
引用 2 楼 u013531238 的回复:
[quote=引用 1 楼 wangnaisheng 的回复:]


int rowIndex=3;//指定行号           

this.dgvInGoodsInfo.Rows[rowIndex].Selected = true;
this.dgvInGoodsInfo.CurrentCell = this.dgvInGoodsInfo.Rows[rowIndex].Cells[0];
我隐藏了第一列,就不能指定了、、要怎么做呢?[/quote] Cells[0] -> Cells[1]
save4me 2014-06-25
  • 打赏
  • 举报
回复
参考: C# Set DataGridView Selection

//First is to scroll down the DataGridView so the row is visible in the screen:
//首先滚动到相应的行使其可见
dataGridView1.FirstDisplayedScrollingRowIndex = index;
dataGridView1.Refresh();

//Then you must select the row so that binding sources update their Current item:
//然后设置相应行的第一格为当前单元格
dataGridView1.CurrentCell = dataGrid.Rows[index].Cells[0];

//Finally, you can visually select the row with C#:
//最后设置该行为选中状态
dataGridView1.Rows[index].Selected = true;
伤逝的离别 2014-06-25
  • 打赏
  • 举报
回复
引用 1 楼 wangnaisheng 的回复:


int rowIndex=3;//指定行号           

this.dgvInGoodsInfo.Rows[rowIndex].Selected = true;
this.dgvInGoodsInfo.CurrentCell = this.dgvInGoodsInfo.Rows[rowIndex].Cells[0];
我隐藏了第一列,就不能指定了、、要怎么做呢?
wangnaisheng 2014-06-25
  • 打赏
  • 举报
回复


int rowIndex=3;//指定行号           

this.dgvInGoodsInfo.Rows[rowIndex].Selected = true;
this.dgvInGoodsInfo.CurrentCell = this.dgvInGoodsInfo.Rows[rowIndex].Cells[0];

110,536

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧