The Syncfusion native Blazor components library offers 70+ UI and Data Viz web controls that are responsive and lightweight for building modern web apps.
.NET PDF framework is a high-performance and comprehensive library used to create, read, merge, split, secure, edit, view, and review PDF files in C#/VB.NET.
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 ?
ADAdministrator Syncfusion Team August 16, 2006 12:43 AM UTC
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; }
CGCharbel GereigeSeptember 19, 2006 03:15 PM UTC
is it possible to get the index of the selected rows?
like have int[] SelectedRowsIndex{ get{ int[] selected;
//.... implementation ....
return selected; }
ADAdministrator Syncfusion Team September 20, 2006 04:53 AM UTC
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. } }