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.
Syncfusion Feedback

Proper way to add or remove columns

Thread ID:

Created:

Updated:

Platform:

Replies:

6344 Aug 8,2003 06:05 PM Dec 30,2003 02:03 AM Windows Forms 5
loading
Tags: GridControl
Peter
Asked On August 8, 2003 06:05 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) { }

Peter
Replied On 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(); }

Peter
Replied On 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

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

Peter
Replied On 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;

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

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

;