Reorder of Data Grid columns

SchoolTeacher54
SchoolTeacher54 used Ask the Experts™
on
I have a data grid that I reorder from time to time to reflect the relevant information a user needs to see.
I need to restore the table to the default column layouts and don't have the slightest idea of how to do it. I can sort but not reorder back to default.

What is the secret?

Many thanks
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®
anarki_jimbelSenior Developer

Commented:
Not sure I understand the problem properly...
However, if you are talking about a DataGridView then you may probably use :

dataGridView1.Columns["ColumnName"].DisplayIndex = 0;

Of course you need to record initial column order somehow to be able to restore it later.
AndyAinscowFreelance programmer / Consultant

Commented:
How can you not know the initial ordering - you have the written code / designed queries which contain the original sort order.

Author

Commented:
Andy,

I guess that is the crux of the question (how can I not know...). Instead of keeping track of where the columns end up in code  and further resetting them to default order by keeping track in code, I had hoped that Microsoft thought of a single method to handle moving the columns back to the underlying default. Further I had wondered about a method to call the grid back to the default layout without refilling the grid; which seems to work but it undesirably adds to the round trip to the server.
I found a suggestion to set the data source to null and then rebind it. Works great.

Thank you all!

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial