DataGridView 选中一行

ha09070204 2012-05-14 03:36:07
DataGridView 如何选中每次添加的那条数据,我用Selected可以选中整行,但DataGridView左侧的箭头不能在我选中的那行
请教高手
...全文
241 14 打赏 收藏 转发到动态 举报
写回复
用AI写文章
14 条回复
切换为时间正序
请发表友善的回复…
发表回复
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
this.dgv_Products.CurrentCell = this.dgv_Products.Rows[this.dgv_Products.Rows.Count - 1].Cells[0];
this.dgv_Products.Rows[this.dgv_Products.Rows.Count - 1].Cells[0].Selected = true;
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 11 楼 的回复:]
引用 10 楼 的回复:

C# code

this.dgv_Products.CurrentRow.Selected = true;



选中最后一行试试?


不好意思,2了!!!
[/Quote]
谢了,我已经解决了
Hatake 2012-05-14
  • 打赏
  • 举报
回复
FirstDisplayedScrollingRowIndex是设置显示的第一行
Hatake 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 10 楼 的回复:]

C# code

this.dgv_Products.CurrentRow.Selected = true;



选中最后一行试试?
[/Quote]

不好意思,2了!!!

Hatake 2012-05-14
  • 打赏
  • 举报
回复

this.dgv_Products.CurrentRow.Selected = true;


选中最后一行试试?
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
有没有人会呀,急用
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 7 楼 的回复:]
引用 3 楼 的回复:

C# code

dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;


要判断列表是否有数据
[/Quote]

这个肯定得判断了,不然会报错的
我的代码,真的不行,this.dgv_Products.FirstDisplayedScrollingRowIndex的值一直为0
if (this.dgv_Products.dataGridView1.Rows.Count > 0)
{
this.dgv_Products.Rows[this.dgv_Products.Rows.Count - 1].Selected = true;
this.dgv_Products.FirstDisplayedScrollingRowIndex = this.dgv_Products.Rows.Count - 1;
}
熙风 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C# code

dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
[/Quote]

要判断列表是否有数据
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C# code


dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
[/Quote]
不行啊,我设置了dataGridView1.FirstDisplayedScrollingRowIndex
但dataGridView1.FirstDisplayedScrollingRowIndex的值一直为0
Hatake 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]

C# code

dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
[/Quote]

+1
wlcsdf 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 3 楼 的回复:]
C# code


dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
[/Quote]
正解,学习了
bdmh 2012-05-14
  • 打赏
  • 举报
回复

dataGridView1.Rows[dataGridView1.Rows.Count - 1].Selected = true;
dataGridView1.FirstDisplayedScrollingRowIndex = dataGridView1.Rows.Count - 1;
ha09070204 2012-05-14
  • 打赏
  • 举报
回复
[Quote=引用 1 楼 的回复:]
你是不是设置了多选呢,这样只会将记录添加到集合中,捏可以设置CurrentRow
[/Quote]
我没有设置多选,只是选中最后一行(是我新添加的数据)
怎么设置CurrentRow?
bdmh 2012-05-14
  • 打赏
  • 举报
回复
你是不是设置了多选呢,这样只会将记录添加到集合中,捏可以设置CurrentRow

111,126

社区成员

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

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

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