Search code examples
winformsdevexpressgridcontrol

Devexpress winforms gridcontrol - Get id from selected row on both right and left click event


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.


Solution

  • You can get it by using gridView_FocusedRowChangedevent 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.