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

Reg : Groupinggrid to DataTable

Hi, I am using following code to copy data from grid to datatable. I am facing problem like... I dont want to copy first three column from grid.(Always) How do i do that...? DataTable dt = new DataTable(); int numCols = grid.TableDescriptor.VisibleColumns.Count; foreach(GridVisibleColumnDescriptor cd in grid.TableDescriptor.VisibleColumns) { string s = grid.TableDescriptor.Columns[cd.Name].HeaderText; dt.Columns.Add(new DataColumn(s, grid.TableDescriptor.Columns[cd.Name].FieldDescriptor.GetPropertyType())); } foreach(Record r in grid.Table.FilteredRecords) { DataRow dr = dt.NewRow(); foreach(GridVisibleColumnDescriptor cd in grid.TableDescriptor.VisibleColumns) { string s = grid.TableDescriptor.Columns[cd.Name].HeaderText; dr[s] = r.GetValue(cd.Name); } dt.Rows.Add(dr); } dt.AcceptChanges(); Thanks, Anna

1 Reply

AD Administrator Syncfusion Team August 2, 2005 04:01 AM

Try adding code to both the loops that will skip the first three passes through the loops.
int numCols = grid.TableDescriptor.VisibleColumns.Count;
int i = 0;
foreach(GridVisibleColumnDescriptor cd in grid.TableDescriptor.VisibleColumns)
 {
	if(i > 2)
	{
		string s = grid.TableDescriptor.Columns[cd.Name].HeaderText;
		dt.Columns.Add(new DataColumn(s, 		grid.TableDescriptor.Columns[cd.Name].FieldDescriptor.GetPropertyType()));
	}
	i += 1;
}

Loader.
Live Chat Icon For mobile
Up arrow icon