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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

Multi row selection / data binding

Thread ID:

Created:

Updated:

Platform:

Replies:

70572 Dec 15,2007 04:46 PM UTC Dec 21,2007 06:45 PM UTC WinForms 6
loading
Tags: GridControl
Christoph Gasser
Asked On December 15, 2007 04:46 PM UTC

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



Administrator [Syncfusion]
Replied On 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();
}



Christoph Gasser
Replied On 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


Administrator [Syncfusion]
Replied On 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



Christoph Gasser
Replied On 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


Administrator [Syncfusion]
Replied On 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

Christoph Gasser
Replied On 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


CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

Warning Icon You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.Close Icon

;