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

Programmatic row selection in grid grouping control

Hi,

I'm having problems programmatically selecting and clearing a row in the grid grouping control.

I've set the grid up as per the examples to act as a list box, so when any cell is selected, the entire row appears selected and the back color is blue.

I have set the following properties...

TableOptions.ListBoxSelectionMode = SelectionMode.One

TableOptions.SelectionBackColor = Highlight (blue)

TableOptions.SelectionTextColor = HighlightText (white)

TableOptions.ListBoxSelectionColorOptions = ApplySelectionColor

TableOptions.ListBoxSelectionCurrentCellOptions = WhiteCurrentCell

In my CurrentCellActivating event I set the ColumnIndex = 0 as per the example.

Selection works fine when the user makes a selection with the mouse. The whole row gets selected, the background color is blue and only the columns have the background color blue.

If i programmatically select a row using TableModel.Selections.SelectRange or TableModel.Selections.Add then I get the selection in black and the entire width of the grid control appears higlighted in black rather than only the columns (there are not enough columns to go to the far edge of the grid control)

I also want to remove the selection if the grid looses focus. This works if the selection was made programitically, but doesn't if the user selected the row with the mouse.

How can I get the programmatic selection to work the same as the use selection. And how can I remove the user selection programmatically?

Thanks in advance,

Ben.

4 Replies

AD Administrator Syncfusion Team February 5, 2007 11:28 AM UTC

I've solved my own problem.

Before I was using the following method to select the row.

grid.TableControl.Model.Selections.Add(GridRangeInfo.Row(rowIndex)

If I use grid.Table.SelectedRecords.Add(grid.Table.DisplayElements[rowIndex].GetRecord());

then it works. I also use the SelectedRecords collection to clear the selection on lost focus.

I would still be greatful if someone could explan what the difference is between Table.SelectedRecords and Model.Selections, and perhaps why there is a difference at all !

To be honest I only found this solution by chance, not because I understood the various selection methods used by the grid.

Thanks,

Ben.


AD Administrator Syncfusion Team February 5, 2007 01:00 PM UTC

The selections you see using Model.Selections is behavior inherited from GridControlBase. Depending upon AllowSelections settings, these selections may be groups of cells,rows, columns and combinations of these different selection type. This selection architecture inherited from GridControlBase has no special knowlegde of GridGroupingControl (bound data, nested tables, etc.).

The selections you see using Table.SelectedRecords is a selection architecture within GridGroupingControl itself. It does have special knowlegde of GridGroupingControl, and can work within nested tables, etc. You specify you want to use this selection support by setting TableOptions.ListBoxMode to something other than none and at the same time, setting TableOption.AllowSelection = none (the default setting).


SR Sérgio Rodrigues Costa November 18, 2015 12:14 AM UTC

I was trying to find a solution to programatically select all rows in a GridgroupingControl and I found your question.
Well, maybe it is just a variant of what you want but, to help someone else to do the same, here it goes.

this.gridDataBoundGrid1.Model.Selections.Add(Syncfusion.Windows.Forms.Grid.GridRangeInfo.Rows(1, this.gridDataBoundGrid1.Model.RowCount));

Best regards,

Sergio Costa


SA Solai A L Syncfusion Team November 18, 2015 11:08 AM UTC

Hi Sergio,


Thank you for your update.


We are glad to know that your requirement has been achieved. Please let us know if you need any further assistance in future.


Thanks,
Al.Solai.

Loader.
Live Chat Icon For mobile
Up arrow icon