Quantcast
Viewing all articles
Browse latest Browse all 12583

Right click to select a row in a DataGridView

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.AppointmentsDataGridView.CurrentCell = Me.AppointmentsDataGridView.Rows(e.RowIndex).Cells(e.ColumnIndex)

EndIf


Just wondering if there is a better way of doing this as it is sure to be a common problem.

GS

Viewing all articles
Browse latest Browse all 12583

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>