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

Proper way to add or remove columns

What is the proper syntax for adding or removing columns in a databoundgrid. using this method does not work properly. private void resetColumns(GridBoundColumn[] cols) { }

5 Replies

PE Peter August 8, 2003 06:11 PM

What is the proper syntax for adding or removing columns in a databoundgrid. using this method does not work properly. private void resetColumns(GridBoundColumn[] cols) { gridDataBoundGrid1.SuspendLayout(); // tried this way also // gridDataBoundGrid1.DataGridModel.ColCount = cols.GetUpperBound(0) + 1; gridDataBoundGrid1.GridBoundColumns.Clear(); gridDataBoundGrid1.GridBoundColumns.AddRange(cols); gridDataBoundGrid1.DataGridModel.ColCount = cols.GetUpperBound(0) + 1; gridDataBoundGrid1.ResumeLayout(); }


PE Peter August 8, 2003 06:14 PM

the problem this causes is not all columns are visible I have tried setting the number of columns before and adding the GridBoundColumn[] but the problem still persists, any suggestions as to what im doing wrong


AD Administrator Syncfusion Team August 8, 2003 06:15 PM

You remove them directly from the grid.GridBoundColumns (if you explcitly added them), or from the grid.Binder.InternalColumns. You can use either Remove or RemoveAt.
private void button1_Click(object sender, System.EventArgs e)
{
	this.gridDataBoundGrid1.Binder.InternalColumns.RemoveAt(1);
	this.gridDataBoundGrid1.Model.ColCount--;
	this.gridDataBoundGrid1.Refresh();
}


PE Peter December 29, 2003 06:00 PM

After removing the column and then adding them back the data is no longer on the grid. It is still bound to the dataview, the mappingNames are still set and the data is still on the dataview. Is there a special way to add columns? who's mappings have been previously removed;


AD Administrator Syncfusion Team December 30, 2003 02:03 AM

You will need to rebuild the entire collection to inset a GridBooundColumn into the GridBoundColumnsCollection.
private GridBoundColumn saveCol = null;
private void button1_Click(object sender, System.EventArgs e)
{//save and delete item 1
	saveCol = this.grid.Binder.InternalColumns[1];
	this.grid.Binder.InternalColumns.RemoveAt(1);
	this.grid.Model.ColCount--;
	this.grid.Refresh();
}

private void button2_Click(object sender, System.EventArgs e)
{//insert the saved column at item 1
	GridBoundColumnsCollection gbcc = this.grid.Binder.InternalColumns;
	GridBoundColumn[] boundCols = new GridBoundColumn[gbcc.Count + 1];
	int insertLocation = 1;
	int offSet = 0;
	for(int i = 0; i < gbcc.Count + 1; ++i)
	{
		if(i == insertLocation)
		{
			boundCols[i] = saveCol;
			offSet = 1;
		}
		else
		{
			boundCols[i] = gbcc[i - offSet];
		}
	}
	gbcc.Clear();
	gbcc.AddRange(boundCols);
	this.grid.Model.ColCount++;
	this.grid.Refresh();
}

Loader.
Live Chat Icon For mobile
Up arrow icon