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

Multi-select in GridDataBoundGrid

Hi! I''ve been looking and searching through the forums and I haven''t found an answer to my problems yet! I have a lookup-form with a griddataboundgrid on it... it gets filled with a dataset which contains one datatable. extended multi select is enabled. now when I select multiple rows, I need to get the associated datarows out of my dataset when I press the ok button so that I can pass a DataRowCollection to the form that has called the lookup-form. this.datagrid.selections.getselectedrows() gives back a gridrangeinfolist but where do I get my datarows from there on?? or am I looking at the wrong place? any help would be greatly appreciated :)

11 Replies

AD Administrator Syncfusion Team August 25, 2005 10:51 AM UTC

Using GetSelectedRows will give you a GridRangeInfoList. From the GridRangeInfoList, you get GridRangeInfo objects that are row ranges, so range.Top and Range.Bottom will give you the the indexes of the selected rows in the grid. So, you have a collection of grid rowIndex''s. To get the corresponding position in your datasource, you use this method. int position = this.grid.binder.RowIndexToPosition(rowIndex); If you are not supporting sorting or filtering in your data source, then you can just use this position value to index your data source (DataTable.Rows[position]). But if you are allowing sorting/filtering, to get the datarow from the position, you need to go through the DataView associated with the grid and your datasource.


AD Administrator Syncfusion Team August 25, 2005 12:15 PM UTC

at first sight, it works like a charm! thanks a lot!!! :)


KP Keyur Patel September 3, 2005 12:07 AM UTC

I was having the same problem. What if the rows selected are not sequential (i.e. they were selected using clicks)? The top and bottom is not what I need, I need a list of rows that were selected.


AD Administrator Syncfusion Team September 3, 2005 12:27 AM UTC

You get the selected rows the same way. The GridRangeInfoList gives you a collection of GridRangeInfo objects. From each one of these GridRangeInfo objects, you can use the range.Top and range.Bottom to find the rows contained in that particular range. If Top equals Bottom, then that would represent a single row, selected with a click. If you clicked 5 individual rows to select them, there would be 5 GridRangeInfo objects where Top == Bottom for each range.


BK Babak Keradman November 12, 2005 08:29 PM UTC

This does not seem to work well when the grid has been grouped. For instance, if the GridRangeInfo is telling me that I am "R14", there doesn''t seem to be a way to translate that to the index in the datasource, because there may be many grouped rows. R14 could be index 75 if I have many rows grouped. Is there a way around this?


AD Administrator Syncfusion Team November 12, 2005 09:48 PM UTC

The above discussion was for a GridDataBoundGrid. It uses the selection support in the GridControlBase class. This class has no knowledge of the special nature of the GridGroupingControl. That control has its own selection support that differs from the support in the base class. To use it, set: grid.TableOptions.AllowSelections = GridSelectionFlags.None; grid.TableOptions.ListBoxSelectionMode = Selection.Mode.One; //anything other than None Then you can use the this.gridGroupingControl1.Table.SelectedRecords collection to access the selected records.


BK Babak Keradman November 12, 2005 10:04 PM UTC

When I set my options to: grid.TableOptions.AllowSelections = GridSelectionFlags.None; grid.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended; //or MultiSimple this.gridGroupingControl1.Table.SelectedRecords always returns a count of 1 selected record, no matter how many records that I select.


AD Administrator Syncfusion Team November 12, 2005 10:32 PM UTC

I do not see this problem in this sample using version 3.3. Can you see this problem in this sample? http://www.syncfusion.com/Support/user/uploads/GGC_Sel_7f950c4c.zip


BK Babak Keradman November 12, 2005 10:41 PM UTC

There are two differences between our implementation and the sample. 1-) We do not use this.gridGroupingControl1.DataSource; but rather this.gridGroupingControl1.ControlDataSet 2-) Our datasource is a DataSet not a DataTable Other than that my code looks the same as the sample. I put in the following test button: Syncfusion.Grouping.SelectedRecordsCollection selectedRecords; selectedRecords = grdTOPWatchList.Table.SelectedRecords; MessageBox.Show(selectedRecords.Count + " selected record(s)..."); No matter how many records I select, the count is always only one.


AD Administrator Syncfusion Team November 12, 2005 11:08 PM UTC

Are you using the Windows Forms GridGroupingControl or the web GroupingControl? The web forum is here. http://www.syncfusion.com/Support/Forums/forum.aspx?ForumID=14


AD Administrator Syncfusion Team November 12, 2005 11:18 PM UTC

One other comment is that is you are using nested tables, then there is a SelectedRecords selection for each table. Console.WriteLine(this.gridGroupingControl1.Table.SelectedRecords.Count); string s = this.gridGroupingControl1.TableDescriptor.Relations[0].ChildTableName; Console.WriteLine(this.gridGroupingControl1.GetTable(s).SelectedRecords.Count);

Loader.
Live Chat Icon For mobile
Up arrow icon