IFlyHigh
IFlyHigh

Reputation: 546

Set Focus on row by cell value

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

Upvotes: 1

Views: 7030

Answers (4)

Ahmed Soliman
Ahmed Soliman

Reputation: 446

for devExpress use this code :

gridView1.FocusedRowHandle = gridView1.LocateByValue("columnName",value of columnName, null); 

Upvotes: 0

nempoBu4
nempoBu4

Reputation: 6631

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

Upvotes: 2

Meysam Tolouee
Meysam Tolouee

Reputation: 579

    private void PositionsNotReadyListGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
        this.PositionsNotReadyListGridView.Rows[e.RowIndex].Selected = true;
    }

Upvotes: 0

Mohamed
Mohamed

Reputation: 520

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;

Upvotes: 0

Related Questions