Question

I have two grid views namely PositionsReadyListGridView and PositionsNotReadyListGridView.

Now the functionality requirement is on click of Button Set Not Ready the selected item from PositionsReadyListGridView is removed from this list and added to PositionsNotReadyListGridView.

Similarly on click of Button Set Ready the selected item from PositionsNotReadyListGridView is removed from this list and added to PositionsReadyListGridView.

I have implemented this functionality but I am unable to set Focus on the latest row which is added to the either of the GridView.

Is there a way that I can set Focus to the row according to cell values?

For example in both of the Grids I have a column colID which is unique to a row.

Can I somehow use this ID to set Focus to the row added to either PositionsReadyListGridView (on Set Ready click) or PositionsNotReadyListGridView (on Set Not Ready Click)?

Thanks

Was it helpful?

Solution

You can use LocateByValue method, which returns RowHandle of located row and set this value to FocusedRowHandle property:

int rowHandle = PositionsReadyListGridView.LocateByValue("colID", ID);
if (rowHandle != GridControl.InvalidRowHandle)
    PositionsReadyListGridView.FocusedRowHandle = rowHandle

OTHER TIPS

to get the lately added row get it by

PositionsReadyListGridView.Rows.Count - 1

and for setting the focus

PositionsReadyListGridView.Rows[PositionsReadyListGridView.Rows.Count - 1].Cells[colID].Selected = true;
    private void PositionsNotReadyListGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
        this.PositionsNotReadyListGridView.Rows[e.RowIndex].Selected = true;
    }

for devExpress use this code :

gridView1.FocusedRowHandle = gridView1.LocateByValue("columnName",value of columnName, null); 
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top