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 row selection / data binding

I have a GridGroupingControl with databinding. Now I want to run a function that deletes all the object behind each row (one row / one object). What I found out is, that I can get all the selected rows with this code:

foreach (SelectedRecord rec in this.gridGroupingControl.TableModel.Table.SelectedRecords)
{
}

But hwat I don't know is, how to get the link to the databound object?

I found also another example:
GridRangeInfoList rangeList = gridDataBoundGrid1.Selections.GetSelectedRows(true, false);

CurrencyManager cm = gridDataBoundGrid1.BindingContext[gridDataBoundGrid1.DataSource, gridDataBoundGrid1.DataMember] as CurrencyManager;

if (cm != null)
{
DataView dv = cm.List as DataView;
if (dv != null)
{
foreach (GridRangeInfo range in rangeList)
{
for (int row = range.Top; row <= range.Bottom; ++row)
{
DataRow dr = dv[gridDataBoundGrid1.Binder.RowIndexToPosition(row)].Row;
Console.WriteLine(dr[0]);
}
}
}
}

But I don't know the part with the currencymanager. What's that? How can I change this to my needs?

Can you help me on that?

Thank you



6 Replies

AD Administrator Syncfusion Team December 16, 2007 02:07 AM UTC

You can get the underlying data object using Selected.Record.GetData(). But if all you want to do is to delete the object, you can try using Record.Delete().

foreach (SelectedRecord rec in gridGroupingControl1.Table.SelectedRecords)
{
// object o = rec.Record.GetData(); //the underlying data object
rec.Record.Delete();
}




CG Christoph Gasser December 19, 2007 10:19 AM UTC

Thank you for your answer. When I call this function (SelectedRecords) I never get objects (SelectedRecord) back (Count = 0) allthough I have selected some rows in the grid.
When I check the Records object there are all the rows = records included (Count = 49).

Any idea what to change so that I get back the objects?

BR
Christoph



AD Administrator Syncfusion Team December 19, 2007 10:46 AM UTC

Have you enabled record selection by setting properties like this:

//turn off the cell selection support inherited from GridControlBase - this support is not aware of the GGC this.gridGroupingControl1.TableOptions.AllowSelection = GridSelectionFlags.None;
//turn on the record selection support in GGC this.gridGroupingControl1.TableOptions.ListBoxSelectionMode = SelectionMode.MultiExtended;


See this KB for information on selections in a GridGroupingControl.
http://www.syncfusion.com/support/kb/grid/Default.aspx?ToDo=view&questId=344




CG Christoph Gasser December 19, 2007 04:36 PM UTC

I#ve tried that already, but no success.

What I have is a GGC with databinding. After binding I do have a lot of Records (Records property). I can check this using .Table.Records.Count .

I've set the parameters as you described in your last answer. I can make selections in the grid.

Then I want to run through all selected records using that code:

foreach (SelectedRecord rec in this.gridGroupingControl.Table.SelectedRecords)
{
//DO THE JOB
}

But as I said, SelectedRecords is always empty (Count = 0).

Sorry for anoying with that.

BR
Christoph



AD Administrator Syncfusion Team December 19, 2007 06:05 PM UTC

Are you using nested tables? If so, the code grid.Table.SelectedRecords only gets the selected records from the parent Table. If you have nested tables, then you would also need to query the Table.SelectedRecords collection for each nested table, maybe using code such as:

gridGroupingControl1.GetTable("ChildRelatedTableName").SelectedRecords


Here is a sample that works for me using teh 6.1 code base to show the underlying data for selected records. Does it work for you? What is different about what you are doing?



WindowsApplication24_4.zip


CG Christoph Gasser December 21, 2007 06:45 PM UTC

After I've set the AlloeSelection property to "None" it workes. Before I had "AlphaBlend, Row, Multiple".

Thank you for your support and the nice example.

Merry Christmas
Christoph


Loader.
Live Chat Icon For mobile
Up arrow icon