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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Text box not lining up correctly on editable flexgrid

Status
Not open for further replies.

Mystic1112

Programmer
Jan 2, 2004
20
0
0
US
I'm trying to build a user control that has an "editable" flexgrid. I've looked at the FAQ 222-3262, but it doesn't address my problem. I am using the following code to position the text box:
Code:
 With hflexgrid
   txtDataEntry.Text = .Text
   txtDataEntry.Visible = True
   txtDataEntry.Move _
    .Left + ScaleX(.CellLeft, vbTwips, UserControl.ScaleMode), _
    .Top + ScaleY(.CellTop, vbTwips, UserControl.ScaleMode), _
    ScaleX(.CellWidth, vbTwips, UserControl.ScaleMode), _
    ScaleY(.CellHeight, vbTwips, UserControl.ScaleMode)
   txtDataEntry.SetFocus
 End With

This, according to all the examples I've been able to find, should work. However, the text box is being offset to the south and east by a seemingly random amount depending on the selected row and column.

I examined the flexgrid's .CellLeft and .CellTop properties, and they are definitely part of the problem. However, I cannot find the correct value to reduce the .CellLeft and .CellTop to get proper placement.

I am trying to create this functionality in a user control instead of directly on the form because I have to use it in several other places.

Please, if you have any suggestions or solutions, I would really appreciate it.

Thanks in advance,
Erika
 
This is all the code that I use to position the floating text box without problems.
Code:
With MSFlexGrid1
   txtFloat.Top = .CellTop + .Top
   txtFloat.Left = .CellLeft + .Left
   txtFloat.Width = .CellWidth
   txtFloat.Height = .CellHeight
   txtFloat.Visible = True
End With

zemp
 
Zemp,
Thank you for your reply. However, the code you have presented doesn't change the behavior of the box. Any suggestions as to why there might be an offset, or where the offset might be coming from?

Thanks.
Erika
 
Am I correct to assume that your text box .appearance and .Borderstyle properties are both = 0?

What exactly is offset? Is it the textbox or the text within the text box? If it is the latter then there is not much you can do. That is something that I have decided to live with. Although you could probably subclass the textbox to align the text within it properly.

zemp
 
Yes, the text box appearance and borderstyle are both zero. By offset I mean that the top and left of the textbox do not line up with the displayed celltop and cellleft. I'll try to draw an ascii picture of the problem.

Grid:
___________
|___________|
textbox:|______________|

That's the closest approximation I can get. Basically, the celltop and cellleft do not match what is actually drawn by the gridlines.
 
Is the grid in another container, such as a tab control? If so you also have to adjust for that container control. Or locate your floating control within the container control as well.


zemp
 
The grid is within a user control, which is within a frame within a tab control. However, if I simply add or subtract the container.Left and container.Top to the equation, I end up with the same problem of some kind of offset being applied that prevents it from lining up.
 
Does this problem occur within a project that includes the usercontrol project or just when you use the ocx in another project? I assume that the textbox is part of the usercontrol. Could it be the grids .left and .top within the usercontrol or something else within the user control?

What event are you using to place the textbox? I use the EnterCell event.



zemp
 
I am using the EnterCell event to place the text box. The problem occurs in the project group that the user control is part of. I have yet to try it when just using the ocx. The grid's .left and .top are at the 0,0 point of the user control.

The user control contains the flexgrid, the textbox, and a combo box.
 
I don't know what else to tell you. I just created a user control with a Lfexgrid and a text box. Placed that project in a project group with a standard project. The standard has a form. The user control is in a frame, on a SStab control on the form. The floating text box works properly. No offset.

Here is my user control info.
Code:
VERSION 5.00
Object = "{5E9E78A0-531B-11CF-91F6-C2863C385E30}#1.0#0"; "MSFLXGRD.OCX"
Begin VB.UserControl UserControl1 
   ClientHeight    =   3600
   ClientLeft      =   0
   ClientTop       =   0
   ClientWidth     =   4620
   ScaleHeight     =   3600
   ScaleWidth      =   4620
   Begin VB.TextBox Text1 
      Appearance      =   0  'Flat
      BorderStyle     =   0  'None
      Height          =   255
      Left            =   1080
      TabIndex        =   1
      Text            =   "Text1"
      Top             =   2760
      Width           =   1095
   End
   Begin MSFlexGridLib.MSFlexGrid MSFlexGrid1 
      Height          =   2535
      Left            =   0
      TabIndex        =   0
      Top             =   0
      Width           =   4575
      _ExtentX        =   8070
      _ExtentY        =   4471
      _Version        =   393216
      Rows            =   15
      Cols            =   8
      FixedCols       =   0
   End
End
Attribute VB_Name = "UserControl1"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = True
Attribute VB_PredeclaredId = False
Attribute VB_Exposed = True
Option Explicit

Private Sub MSFlexGrid1_EnterCell()
   With MSFlexGrid1
      Text1.Top = .CellTop + .Top
      Text1.Left = .CellLeft + .Left
      Text1.Width = .CellWidth
      Text1.Height = .CellHeight
      Text1.ZOrder 0
      Text1.Visible = True
      If Text1.Enabled Then Text1.SetFocus
   End With
End Sub
That last bit is the only code I have.

zemp
 
Zemp,
Thanks for sticking with it this long. I'm sure the solution is something simple that I just haven't found yet.
I'll post it when I do. =)

Erika
 
Mystic1112,

why do you scale the .CellLeft, .CellTop, .CellWidth and .Cellheight properties but not the .Left and .Top properties?

__________________
code is enduring
 
Hokkie,
That's a bit of sloppy code on my part. The .Left and .Top properties of my grid are zero and don't really have an effect on the equation.

Anyone,
I was doing some testing yesterday, moving the app to other machines, and found that the offset is not as pronounced on other monitors. Could there be something about the display I am using that would cause this offset problem?

Mystic
 
I doubt it. I have used this method on distributed apps for years. No one has complained about an offset text box.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top