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.
Unfortunately, activation email could not send to your email. Please try again.

Retrieve Selection from GridDataBoundGrid and get DataRowView[]

Thread ID:

Created:

Updated:

Platform:

Replies:

47865 Aug 15,2006 07:57 AM Sep 20,2006 12:53 AM Windows Forms 3
loading
Tags: GridControl
Daniel Rosenberg
Asked On August 15, 2006 07:57 AM

Hi,

I would need to know the row selection from a GridDataBoundGrid. Non-contiguous row selection are allowed (with shift).

My function written in C# would return
DataRowView[] SelectedRow(GridDataBoundGrid grid)
{
//implementation here
}

I have found about GridDataBoundGrid.Selections.GetSelectedRows()
but I can''t figure out to get a DataRowView[] out of it.
Also read about grid.BindingContext

CurrencyManager cm = (CurrencyManager) grid.BindingContext[grid.DataSource, grid.DataMember];
cm.List but do not know if it will return Selected rows ?


Can you help ?

Thanks,

Daniel

Administrator [Syncfusion]
Replied On August 15, 2006 08:43 PM

Try this code to see if it does what you need.

DataRowView[] GetSelectedDRV()
{
GridDataBoundGrid grid = this.gridDataBoundGrid1;
GridRangeInfoList list = grid.Selections.GetSelectedRows(true, false);
ArrayList al = new ArrayList();
foreach(GridRangeInfo range in list)
{
for(int i = range.Top; i <= range.Bottom; i++)
{
al.Add(i-1); //subtract 1 since DataView is zero base, but grid is 1 based
}
}
CurrencyManager cm = grid.BindingContext[grid.DataSource, grid.DataMember] as CurrencyManager;
DataView dv = cm.List as DataView;
DataRowView[] drvs = new DataRowView[al.Count];
for(int i = 0; i < al.Count; ++i)
{
drvs[i] = dv[(int)al[i]];
}
return drvs;
}

Charbel Gereige
Replied On September 19, 2006 11:15 AM

is it possible to get the index of the selected rows?

like have
int[] SelectedRowsIndex{
get{
int[] selected;

//.... implementation ....

return selected;
}

Administrator [Syncfusion]
Replied On September 20, 2006 12:53 AM

Hi Charbel,

Use the below code snippet to get the selected rows index in a grid.

int[ ] SelectedRowsIndex
{
get{
GridDataBoundGrid grid = this.gridDataBoundGrid1;
GridRangeInfoList list = grid.Selections.GetSelectedRows(true, false);
ArrayList al = new ArrayList();

foreach(GridRangeInfo range in list)
{
for(int i = range.Top; i <= range.Bottom; i++)
{
al.Add(i-1); //subtract 1 since DataView is zero base, but grid is 1 based
}
}
int[ ] selected = new int[al.Count];
al.CopyTo(selected );

return selected ; //It is a zero based index( DataView index), but grid is 1 based.
}
}

Let me know if it does what you need.

Thanks,
Haneef

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.

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.

;