右键单击以选择DataGridView中的行 [英] Right click to select a row in a DataGridView
问题描述
在datagridview上使用上下文菜单时,右键单击不会选择记录。
给出了我在下面修改过的答案,您必须检查用户是否右键单击行标题或列标题( index -1给出错误。) 使用CellMouseDown事件。
When using a context menu on a datagridview right clicking doesn't select the record.
http://msdn.microsoft.com/smartclient/community/wffaq/wf20.aspx#al3sfum0
gives an answer that I have adapted below and you have to check that the user doesn't right click on the row header or column header (index -1 gives an error). Uses CellMouseDown event.
If e.ColumnIndex >= 0 And e.RowIndex >= 0 Then
Me .AdointmentsDataGridView.CurrentCell = Me 。约会DataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex)
Me.AppointmentsDataGridView.CurrentCell = Me.AppointmentsDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex)
结束 如果
只是想知道是否有更好的方法这样做肯定是一个普遍的问题。
GS
推荐答案
好吧,我不知道是否有人还在检查这个节目经过这么多次,但我只想说谢谢你的解决方案。这让我头发乱了好几天了,我简直不敢相信这个优雅的解决方案!
再次感谢你!!
Well, I have no idea if anyone's still checking this thread after all this time, but I just wanted to say THANK YOU for the solution to this. This has had me tearing my hair out for days now, and I can't believe the solution is this elegant!
Thank you again!!
这篇关于右键单击以选择DataGridView中的行的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!