Hi guys help please...I have a DataGridView (dgEvents) and I also want the row to be selected if the user right-click on it. So i have the code below to achieve the right-click select
MouseDown Event Code:
When I try to select a row by using the left-click (mouse left button) the dgEvents.CurrentRow.Index value is right but when i try to use the right-click (mouse right button) the dgEvents.CurrentRow.Index value doesn't change but the highlight is on the row that i've selected (Please see the attched screenshot).Code:private void dgEvents_MouseDown(object sender, MouseEventArgs e) { if (e.Button == MouseButtons.Right) { int indexOver = dgEvents.HitTest(e.X, e.Y).RowIndex; if (indexOver >= 0 && indexOver < dgEvents.RowCount) { dgEvents.Rows[indexOver].Selected = true; } else { dgEvents.ClearSelection(); } } }
Any idea guys on how to solve my problem..Thanks in advance!!!Code:private void dgEvents_SelectionChanged(object sender, EventArgs e) { MessageBox.Show("Selected Index: " + dgEvents.CurrentRow.Index.ToString()); }


Reply With Quote