且构网

分享程序员开发的那些事...
且构网 - 分享程序员编程开发的那些事

我如何选择DataGridView中的最后一行

更新时间:2023-02-05 09:51:25

是的,此控件和文档的整个设计有点误导.尝试改为设置CurrentCell:

Yes, the whole design of this control and documentation is a bit misleading. Try to set CurrentCell instead:

dataGridView1.CurrentCell = dataGridView1.Rows[nRowIndex].Cells[0];



即使您使用选择模式选择整个行,也会在选择时获得理想的效果.您面临的问题是由于在所有情况下都将单元格视为真正的选择对象,而不是一行.对我来说,看起来有些API不一致.无论如何,尝试一下.

顺便说一句,不要使用dataGridView1之类的名称,这违反了Microsoft的命名约定.是的,该名称是由Microsoft Designer创建的,但是谁说您可以保留此名称?所有成员都应在语义上重命名;重新分解引擎是您的朋友.

—SA



It will give you desired effect on selection, even if you use the selection mode to select entire row. The problem you faced was due to the fact that the cell is considered to be a real object of selection in all cases, not a row. To me, it looks like some API inconsistency. Anyway, try it.

By the way, don''t use the names like dataGridView1, this is violation of Microsoft naming conventions. Yes, the name is created by Microsoft Designer, but who said you can keep this names? All members should be renamed semantically; re-factorization engine is your friend.

—SA