Flexgrid onload starts up at negative position but is actually dead center on form (FULLMARKS )

The name almost explains it all, but i will elaborate.
In the form load event, i need to get the position (height &  left) of a specific flex grid that sits on a tab sheet (which i also get the height and left from)

The problem is that in the form load event, some times the flexgrid appears to be sitting at  -1700 when in actual fact it sits at 120. The flexgrid is set to visible = false
however, i dont beleive this to be the problem, since this is intermitant, and only happens sometimes when the form loads. I have tucked do events around it everywhere thinking that it could be a problem with the form loading and then having to execute the code, meanwhile not centering the form correctly, but this does not seem to be the case.

Has anyone else had this issue? or something similar? A clear and correct response will net you full marks + A+
Who is Participating?

Improve company productivity with a Business Account.Sign Up

dbrckoviConnect With a Mentor Commented:
I agree with JMoon5FTM.

Tabbed dialog control (SSTab), and similar, can have several "pages" of controls, and it can display one page at a time, based on the tab button which is active.
At first it seems that all controls are placed on the same place and that Tab control is making everything that does not belong to current page invisible.
This is not true. When you place something to first page (Tab1), and then press Tab2, everything that belongs to Tab1 is moved to the left ( .Left values are negative )
Now if you place something to tab2, and switch back to tab1, everything that was on tab2, is moved left, and controls that belong to tab1 are moved back to their original positions.

Place SSTab control on a form
Place Textbox to Tab0
Place Label to Tab1
Place Picturebox to Tab2
Place Command Button outside SSTab

Private Sub Command1_Click()
    Label1.Left = 0
    Text1.Left = 0
    Picture1.Left = 0
End Sub
Pressing the command button will make all 3 controls visible.
Hi baudspeed,
Are you using any positioning statements within Form_Load (Setting any Tops or Lefts, even if it is for other controls)?
In that case, would you be able to post the relevant code?

JMoon5FTMConnect With a Mentor Commented:
Are you using the TabbedDialog control for your tab sheet?

If so, you need to set the Tab property to the tab the flexgrid sits on.  No control on your form will return accurate positioning information unless its tab is active.
Free Tool: ZipGrep

ZipGrep is a utility that can list and search zip (.war, .ear, .jar, etc) archives for text patterns, without the need to extract the archive's contents.

One of a set of tools we're offering as a way to say thank you for being a part of the community.

If you place a container object (either picturebox or frame control) and size it the same as of the tab page. Place the grid control within the container object. This way in load event you will get the correct position of the grid.

hope this helps!!!
dbrckoviConnect With a Mentor Commented:

That way you will get grid's coordinates inside its container correct, but I think that baudspeed wants to get grid's absolute coordinates ( exact on-screen position where grid is placed )
That would mean that one should add containers coordinates as well.
For example: GridAbsoluteLeft = Form1.Left ( + FormBorderWidth) + SSTab.Left + Picture.Left + Grid.Left

Since Picture box (grid's container) is moved as Tab buttons switch, the value won't be allways the same.
The only way to do this right is, as JMoon5FTM suggested: - to activate the correct tab and then get the coordinates.
The coordinates of the grid will always be the same. If you move the picture box then the coordinates of the picturebox will change but the coordinates of the grid will not change.
They will be the same, but only compared to picture box coordinates.

grid's absolute coordinates (its position on screen or form) are changed as tab buttons are switched, bacouse you have to calculate picture coordinates also.
Since picture coordinates change, so will grid's absolute coordinates.
baudspeedAuthor Commented:
Thanks Guys, Everyones answers were good. I wish i had more points to dole out. But i think i divided them the best way i could.

The tab dialog box must have been a third party object that microsoft bought off a company or something. Its just such a kludgy way of dealing with object controls.

Thanks Again
Kludgy?  Certainly, but I doubt Microsoft could have done better.  You can't actually hide or show a control without changing its Visible property.  The TabbedDialog's developers probably correctly figured that most of us would want the Visible property setting maintained across page navigations, so they had to come up with another way of hiding controls.

Glad I could be of assistance. :)
baudspeedAuthor Commented:
Valid point. I hadnt considered that flipping the visible/invisible flag would lose its original state.
Oh well. Im sure .net does things better
Have a good weekend guys
Well, I think one of the reasons why they have done it this way is becouse controls can't be hidden in design view (when app is not running).
If it would work using "visible" property, then we would have many controls overlaping on the same place in design view, which is not very "programmer - friendly"

Off course, they could have done it by changing the position in design view, and changing "visible" property during run-time. This way controls would allways stay in their place, but unfortunately, this is not the case.

Maybe some of Tabbed Dialog developers will read this thread, and make another "smarter" version of this control. :-)

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

All Courses

From novice to tech pro — start learning today.