SIGN UP MEMBER LOGIN:    
ARTICLE

Updated ReshuffleColumns Method

Posted by Mark Verbraeken Articles | ADO.NET in C# March 20, 2003
Here is an updated version of 'ReshuffleColumns' method of article DataGrid Customization by Mahesh Chand.
Reader Level:

Here is an updated version of 'ReshuffleColumns' method of article DataGrid Customization by Mahesh Chand. To understand the usefulness of this method, you must have to look at DataGrid Customization article. This methods maintains all the properties of the original TableStyle.

public void ReshuffleColumns(DataGridTableStyle tableStyle, int col1, int col2)
{
// init vars
int counter = tableStyle.GridColumnStyles.Count;
string mapName = tableStyle.MappingName;
DataGrid grid = tableStyle.DataGrid;
// Store original columns
ArrayList colStyles = new ArrayList();
for (int i=0; i<counter; i++)
{
colStyles.Add(tableStyle.GridColumnStyles[i]);
}
// Delete columns from tabelstyle
while (tableStyle.GridColumnStyles.Count != 0)
tableStyle.GridColumnStyles.RemoveAt(tableStyle.GridColumnStyles.Count-1);
// Copy columns back to the tablestyle and reorder columns doing so
for(int i=0; i<counter; i++)
{
if(i == col1)
tableStyle.GridColumnStyles.Add((DataGridColumnStyle)colStyles[col2]);
else if(i == col2)
tableStyle.GridColumnStyles.Add((DataGridColumnStyle)colStyles[col1]);
else
tableStyle.GridColumnStyles.Add((DataGridColumnStyle)colStyles[i]);
}
}

Login to add your contents and source code to this article
share this article :
post comment
 
6 Months Free & No Setup Fees ASP.NET Hosting!
Become a Sponsor
PREMIUM SPONSORS
  • ceTE software specializes in components for dynamic PDF generation and manipulation. The DynamicPDF™ product line allows you to dynamically generate PDF documents, merge PDF documents and new content to existing PDF documents from within your applications. Visit DynamicPDF here
    The leading .NET charting control now features PDF, Flash and Silverlight export, visualization of large datasets and more. Deliver true charting functionality to your BI, Scorecard, Presentation or Scientific apps. Download evaluation now.
Team Foundation Server Hosting
Become a Sponsor