Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Windows Forms / WinForm General / September 2006

Tip: Looking for answers? Try searching our database.

DataGridView columns being reordered

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
JFendors - 28 Sep 2006 19:41 GMT
I have a DataGridView which I have configured a set of columns and their fill
weights in the designer.  Also, I have specified a DataPropertyName for each
column.  I programmatically create a BindingSource to hold a set of objects
that I want to display in the DataGridView.  I then assign the BindingSource
as the DataSource of the grid view.

The binding works ok and the data displays in the grid view.  However, it
will randomly (?) rearrange a column in the grid view.  So if my columns were
1, 2, 3, 4, it would end up as 1, 2, 4, 3.  But all the data is in the right
place.  Does anyone know what would cause this and how it can be prevented?
Bob Powell [MVP] - 28 Sep 2006 22:01 GMT
Recent changes to the TypeDescriptor mean that properties are not
necessarily ordered in the same way every time. Automatic generation of
columns depends on property order in the list of PropertyDescriptor objects
but I'm not sure as to the situation with columns created in the designer.
Maybe they follow property order to some extent too.

You can specify that the grid should not auto-generate columns and
explicitly create them yourself or you can create a custom property order
using the new TypeDescriptionProvider system and order your properties in
any way you desire.

In an implementation that I designed I defined an Index attribute that
enables me to sort properties that come from the TypeDescriptor into a
specific numerical order. I'd give you code but it's for a client but
hopefully you get the picture... These solutions are heavily based on a good
knowledge of reflection.

Signature

Bob Powell [MVP]
Visual C#, System.Drawing

Ramuseco Limited .NET consulting
http://www.ramuseco.com

Find great Windows Forms articles in Windows Forms Tips and Tricks
http://www.bobpowell.net/tipstricks.htm

Answer those GDI+ questions with the GDI+ FAQ
http://www.bobpowell.net/faqmain.htm

All new articles provide code in C# and VB.NET.
Subscribe to the RSS feeds provided and never miss a new article.

>I have a DataGridView which I have configured a set of columns and their
>fill
[quoted text clipped - 13 lines]
> place.  Does anyone know what would cause this and how it can be
> prevented?

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.