Reputation:
I am trying to learn Devexpress winforms gridcontrol in my software expertise course. I have not managed yet to get id from selected row both right and left click event. I want an event that triggered both right and left click and meanwhile I want to get selected row id (or first cell value.). If I manage to get row id, I don't want to show id into row. But if not, I will show id into first cell and trying to get firs cell value.
Upvotes: 0
Views: 2605
Reputation: 506
Just to add to Triple K's solution, here's how you can detect which mouse button was clicked in, say the Click event of the grid by casting "e" to DXMouseEventArgs:
private void gridView1_Click(object sender, EventArgs e)
{
if (((DXMouseEventArgs)e).Button == System.Windows.Forms.MouseButtons.Right)
{
string ID = gridView1.GetFocusedRowCellValue("ID").ToString();
MessageBox.Show("ID: " + ID);
}
}
Upvotes: 1
Reputation: 399
You can get it by using gridView_FocusedRowChanged
event because Left or Right click
will fire the event.
Here is a sample code to get ID
from FocusedRow
private void gridView_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e)
{
string ID = gridView.GetFocusedRowCellValue("ID").ToString();
}
Hope it's what you want.
Upvotes: 2