We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy. Image for the cookie policy date

Trying to highlight a row programatically

I am trying to highlight the row of the datagrid that contains a specific value in a field. The datagrid has the ListBoxSelection set to One. The grid also has code for the currentcellmoving and currentcellactivating which set the column to column 0. The code which is failing looks like this... intSelectedRow = 0 intRow = 1 Do While intRow < grid1.RowCount If grid1(intRow, 1).CellValue = strVehicleId Then intSelectedRow = intRow Exit Do End If intRow = intRow + 1 Loop If intSelectedRow <> 0 Then Me.grid1.Focus() Me.grid1.CurrentCell.MoveTo(intSelectedRow, 0, GridSetCurrentCellOptions.SetFocus Or GridSetCurrentCellOptions.ScrollInView, False) End If The loop that searches for the value in column 1 works because the intSelectedRow value is set to a value other that zero. However, the call to highlight the row is not working. I also tried a variation in which I move to the cell and then invoked a single click, but that did not work either. Me.grid1.Focus() Me.grid1.CurrentCell.MoveTo(intSelectedRow, 0) Me.grid1.ActivateCurrentCellBehavior = GridCellActivateAction.ClickOnCell Any suggestions would be greatly appreciated. Thank you for your help.

2 Replies

AD Administrator Syncfusion Team April 16, 2003 01:22 PM UTC

Where are you trying to do this? If it is before the grid has been drawn, so in FormLoad, then try setting this property to see if that will allow things to work. this.gridControl1.ForceCurrentCellMoveTo = true;


CJ Clifton Jones April 16, 2003 01:40 PM UTC

> Where are you trying to do this? > > If it is before the grid has been drawn, so in FormLoad, then try setting this property to see if that will allow things to work. > > this.gridControl1.ForceCurrentCellMoveTo = true; > > > The code is in the Form load event. Your suggestion worked. Thanks

Loader.
Live Chat Icon For mobile
Up arrow icon