Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chris Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

alignment of custom textboxes in a grid

Status
Not open for further replies.

Stefan5627

Programmer
Jul 23, 2002
71
NL

Hi all,

In my editable grids i change the currentcontrol in columns so i can use custom textboxes
however these are not properly alligned with the default textboxes in other (none editable) columns where currentcontrol has not been changed.
when the column with the custom textbox gets the focus, the custom textbox does allign properly.
How can I show the grid with all the textboxes properly alligned without having to set the focus to each column first?
Doing that in a 35 column grid takes about 1.7 seconds.

simple example off a custom textbox:

Code:
define class grid_textbox as Textbox
	
	fontsize = 8
	borderstyle = 0
	margin = 0
	
	FUNCTION InterActivechange
		*	custom code here
	ENDFUNC
	
	FUNCTION Valid
		*	custom code here
	ENDFUNC
	
enddefine

The way I add it to the column (poColumn):

Code:
poColumn.addObject( "customtextbox", "grid_textbox")
poColumn.currentcontrol = "customtextbox"
poColumn.customtextbox.visible = .T.
poColumn.sparse = .F.

Am I forgetting something?
 
What alignment is wrong? horizontal or vertical?

Fontsize 8? Is it the font size for the rest of the columns, too? Not only at design time, but also at run time? Same Font?

I don't get that effect directly using the base textbox this way:

Code:
This.Columns(1).AddObject("Text2","Textbox")
This.Columns(1).Text2.BorderStyle = 0
This.Columns(1).Text2.Visible = .T.
This.Columns(1).CurrentControl = "Text2"
This.Columns(1).Sparse = .F.

Bye, Olaf.
 
The text in the textbox is shifted up 1 or 2 pixels
When you click in the cell it goes down 2 pixels and aligns with the other columns.
font/Fontsize is the same in the entire grid.

I create the grid completely in code (columncount, headercaptions, controlsource, columnwidths, etc..)
That shouldn't make a difference, should it?

The customclasses i use are subclassed from the grid_textbox
 
Using my code I see a shift of the text 1px to the right, when I focus Column1, and back 1px to the left, when leaving. Most probably because I didn't care about Margin, and it's 2 for a base Textbox instead of 0 for a grid column textbox.

If you're so concerned about the look, you could rather use BindEvents() of the normal Text1 textbox events to an eventhandler class instead of a custom textbox. For the beginning, you can stay with the custom textbox, but keep it invisible and don't change currentcontrol and sparse. Instead bind Text1.Interactivechange to customtextbox.Interactivechange etc.

I have the strong assumption though you do everything completely in code, at the essential moment the grid reconstruction turns back readonly columns to their layout defaults, eg fontsize 9.

You could check that out, if you set a totally different font, for debugging purposes, to see if your coded columns really are and stay the way you create and set them. It's a bit unlikely, as your custom textboxes surely work, otherwise you'd notice their code not running. But who knows? It's the only idea I have.

Maybe also go the full custom way and exchange every textbox, readonly or not, so the grid does not draw it's internal textbox anyway, but all columns are customised.

Bye, Olaf.
 

Thank you for the reply Olaf,

Binding/unbinding is a good suggestion, allthough be it a big switch.
Setting sparse to true also looks like a good workaround.
Will try this later, don't have time right now...

@Craig: borderstyle is set to 0 (see class grid_textbox in post above)
 
You could also try to play with Backgroundstyle and see, if RemoveObject("Text1") would help, if you want to stay with your custom textbox.

Sparse=.t. was not a suggestion, it's just natural to keep it .t. if you don't really set the currentcontrol to the custom textbox, but just use it as an eventhandler class. It's code will run, but it will not be the active control, so there is no need to set Sparse to anything, then.

@Craig, if you meant me, I also set BorderStyle=0, see my code.

Bye, Olaf.
 
Not setting Sparse to false but stay with .T. did the trick for me, no matter if removing Text1 or setting Backstyle = 0 or not.

But this will only be applicable for Textboxes. If adding a combobox or Editbox you rather will want to set Sparse = .F.

So I'd rather take the pixelshift of the values when focusing a grid cell as another hint of which cell has focus additional to the blue borderline appearing.

Bye, Olaf.

 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top