3 Replies - 578 Views - Last Post: 27 May 2012 - 02:59 AM Rate Topic: -----

#1 mpooley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-March 11

very strange problem with datagridview column re-ordering

Posted 26 May 2012 - 01:34 PM

So I have a really weird problem here it's going to be hard to explain so bear with me please.

I have a user control which consists of a dataviewgrid with some extra panels controls etc.

I have just updated this program from an old version of vb where the tab control was just a row of tabs with no actual child pages attached.

so to use several of these userControls (called 'Pages' from now on) a Panel was created and placed underneath the tabs to give the illusion of tabpages.
when a user clicked a tab the relevant 'Page' was brought to the top of the Z order. This was accomplished with a directory of the 'Pages'
This all worked fine until I decided to change to using the TabControl in VS 2010.

So I didn't need the Panel anymore I just added the 'Pages' to the TabPages instead and I could also get rid of the directory to access the pages as
it is not needed for display purposes anymore and for other access I could use the Tabcontrol.TabPages collection instead.

Now when each 'page' is created and setup the dataviewgrid is loaded with a Table and the columns are re-ordered.

I am loading approx 20 'pages' to the tabcontrol 1 to each newly created tabpage obviously.
this is done using using a for each loop from a DB table.

now the problem is that the first 'page' dataviewgrid has the columns re-ordered but none of the others do ! the Data is fine it's just the column order that's wrong.
the same code is used for all (The setup is method of the 'Page') and i have stepped through the code and it all works OK with no exceptions.
no code is missed but the grid order is OK for the first 'page' but not the others.
everything else works fine the 'Pages' are all on the TabPages and the data is OK

Now comes the really weird bit! if I add the 'page' to the old unused panel before i add it to the Tabpage all the grids are re-ordered fine!
as in
 
MainPanel1.Controls.Add(MyAccountsUserPage)
myTabPage.Controls.Add(MyAccountsUserPage)



Now the Panel is visible but not on screen if you see what i mean -
obviously if i move it on screen it's empty as the 'page' control can only be in one place and it's on the Tabcontrol !
so why is it working ONLY when I add it first to the unused Panel? what is happening here?

Oh BTW it only works for this Panel - not if i create a new one and add it to that!
AND if the Panel Visible property is set to false the columns are not re-ordered again??

I have tried deleting the panel and all code that uses it but the grids are not ordered properly till i re-instate the panel?
all the redundant code that used to use the panel is deleted except for the line above

I am only a hobby programmer and I think i must be missing something fundamental/obvious

I hope I have given enough information here - I don't think i need to give all the code as it would be fairly difficult and it all works perfectly except for this strange fault

can anyone help please as I am stumped.

thanks

Mike

Is This A Good Question/Topic? 0
  • +

Replies To: very strange problem with datagridview column re-ordering

#2 m_wylie85  Icon User is offline

  • D.I.C Addict
  • member icon

Reputation: 95
  • View blog
  • Posts: 882
  • Joined: 15-October 10

Re: very strange problem with datagridview column re-ordering

Posted 26 May 2012 - 02:22 PM

This is quite hard to follow can you send me your project in a zip file so i can see what is happening also send the database so i have the data to load into this
Was This Post Helpful? 0
  • +
  • -

#3 mpooley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-March 11

Re: very strange problem with datagridview column re-ordering

Posted 27 May 2012 - 01:44 AM

View Postm_wylie85, on 26 May 2012 - 02:22 PM, said:

This is quite hard to follow can you send me your project in a zip file so i can see what is happening also send the database so i have the data to load into this


Sorry couldn't do that as lots of personal financial data in the DB.
I agree it's hard to follow though.
The nub of it must lie in what happens internally in VB when you place an instance on the panel. I would have thought?

Thanks

Mike
Was This Post Helpful? 0
  • +
  • -

#4 mpooley  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 17
  • Joined: 09-March 11

Re: very strange problem with datagridview column re-ordering

Posted 27 May 2012 - 02:59 AM

I have found a solution to this problem which means i don't have this kludge of having to load the 'Page' into the panel first.

I had another look into the re-ordering of the datagrid columns.
and found that I really only needed to move the row number column from index 0 to index 9 The other columns shifted down one automatically which i didn't realise when i first wrote the code so i removed the code that set all the other columns and now I don't get the problem?
I would love to know why the Kludge of moving it to the panel first made it work but unless anyone has any idea's I suppose I'll never know!
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1