1

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

Hassan
  • 5,360
  • 2
  • 22
  • 35
IFlyHigh
  • 546
  • 2
  • 9
  • 20

4 Answers4

2

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
nempoBu4
  • 6,521
  • 8
  • 35
  • 40
0

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;
Mohamed
  • 470
  • 3
  • 14
  • Hi Mohamed, the problem is changes in the list are done at DB Level and after changes are done new lists are binded again to gridviews. So the chances are that the position of new row could be anywhere in the grid. – IFlyHigh Apr 22 '14 at 09:45
  • Then, try to get the "UpdatedTime" from DB and use that to order your data. else use that to select the updated row – Mohamed Apr 22 '14 at 09:47
  • By saying latest row I meant that user can select multiple rows at a time and set them Ready or NotReady in that case the Focus should be on the last row which is setted to Ready or NotReady but again this last row could be placed anywhere in the GridVews(first,last,middle) as GridViews have Groups and new row will be placed in respective Group. – IFlyHigh Apr 22 '14 at 09:48
  • When user set them ready/not ready does it hit the database? save and fetch it back and bind to the grid? – Mohamed Apr 22 '14 at 09:50
  • I am not actually resetting the binding just assigning the datasource again to the new list like this : this.PositionsListInvoiceReadyBindingSource.DataSource = _list_PositionsReady; this.PositionsListInvoiceReadyBindingSource.RaiseListChangedEvents = true; this.PositionsListInvoiceReadyBindingSource.ResetBindings(resetBindings); – IFlyHigh Apr 22 '14 at 10:00
  • try to have one more property(DateTime) for this list. whenever a new row is added to this list add with the time stamp. then it will be easy for you to locate the latest modified row. – Mohamed Apr 22 '14 at 10:21
0
    private void PositionsNotReadyListGridView_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
    {
        this.PositionsNotReadyListGridView.Rows[e.RowIndex].Selected = true;
    }
Meysam Tolouee
  • 569
  • 3
  • 17
0

for devExpress use this code :

gridView1.FocusedRowHandle = gridView1.LocateByValue("columnName",value of columnName, null); 
Ahmed Soliman
  • 416
  • 5
  • 11