Click here to Skip to main content
15,943,103 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hi Friends,

DevExpress gridcontrol how we get selected row values in grid view key down event.


Thanks in Advance....

Vineetha.K.Ravindranath
Posted

Use the events of the GridView: RowClick and FocusedRowChanged.

By example:

C#
//RowClick Event for to detect the row to press click on GridView
private void myGrid_RowClick(object sender, DevExpress.XtraGrid.Views.Base.RowClickEventArgs e) {
    //Validating selected row
    if (e.RowHandle < 0) {
        //Writing code for invalid row selected
    } else {
        //Recover information about row using some method: GetRow(), GetRowCellValue(), etc
        register = (MyClass)myGrid.GetRow(e.RowHandle)).ShallowCopy();
        oneValueOfCellOfRow = myGrid.GetRowCellValue(e.RowHandle, "OneNameOfFieldNameOfGrid");
    }
}

//FocusedRowClick for detect when you move into grid with directons keys
private void myGrid_FocusedRowChanged(object sender, DevExpress.XtraGrid.Views.Base.FocusedRowChangedEventArgs e) {
    //Validating selected row
    if (e.FocusedRowHandle < 0) {
        //Writing code for invalid row selected
    } else {
        //Recover information about row using some method: GetRow(), GetRowCellValue(), etc
        register = (MyClass)myGrid.GetRow(e.FocusedRowHandle));
        oneValueOfCellOfRow = myGrid.GetRowCellValue(e.FocusedRowHandle, "OneNameOfFieldNameOfGrid");
    }
}


Attention:

When i asign the DataSource to Grid, i assing to DataSource a List of MyClass

C#
List<myclass> data = new List<myclass>();
//Some code to fill the data (using POCOS)
...
//Assing the data to DataSource
myGrid.DataSource = data;
</myclass></myclass>
 
Share this answer
 
Comments
Vineetha Ravindranath 16-Feb-13 4:26am    
Thank you for your solution...
You may have better luck posting this question to the Devexpress forums[^]. The target audience will be better there.
 
Share this answer
 
Comments
Sandeep Mewara 15-Feb-13 15:51pm    
My 5 to the answer. Sage advice.
fjdiewornncalwe 15-Feb-13 16:48pm    
Thanks, Sandeep

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900