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

MSHFlexGrid cell alignment

Status
Not open for further replies.

happyabc

IS-IT--Management
Mar 10, 2004
164
IN
I am trying to position a text-box EXACTLY over a MSHFG in order to make it write-also but it is always shifted a bit to bottom-right. How to get it to cover the cell exactly?
 
Can you post your code? Maybe we can see what the problem is.

This is the basic code that I always use to position a text box over a FlexGrid cell.
Code:
   txtFloat.top = Grid.CellTop + Grid.top
   txtFloat.Left = Grid.CellLeft + Grid.Left
   txtFloat.width = Grid.CellWidth
   txtFloat.Height = Grid.CellHeight




zemp
 
I'm using the same code except that I didn't offset it by Grid.Top and Grid.left. I just tried that and it doesn't maake any difference. There's a lot of confusion about borders generally in my mind and I've never come accross any full details anywhere. Has anyone seen FULL info on this topic?
 
this is the code I always use to show a flat textbox without borders over a MSHFlexgrid cell. Replace txtCellEditor with your txtFloat, and maybe for best results you could tweak the position of the textbox one pixel at a time to see what works best. You can do this in the .move method of the textbox.

Note: this code comes straight from my app, so it's not modified to suit your needs. But see the bit where the textbox is put in front of the Flexgrid and given the dimensions of the cell.

Code:
Dim cellRow As Long, cellCol As Long

Sub ShowCellEditor()
  With mhfgCDRS
    ' Cancel range selection
    .RowSel = .Row
    .ColSel = .Col
 
    ' Move the textbox into place
    txtCellEditor.Move .Left + .CellLeft, .Top + .CellTop, _
        .CellWidth - ScaleX(1, vbPixels, vbTwips), _
        .CellHeight - ScaleY(1, vbPixels, vbTwips)

    ' Transfer the contents of the current cell into the textBox
    txtCellEditor.Text = .Text

    ' Move the TextBox in front of the grid
    txtCellEditor.Visible = True
    txtCellEditor.ZOrder
    txtCellEditor.SetFocus

    ' Remember coordinates for later
    cellRow = .Row
    cellCol = .Col

  End With
End Sub

__________________
code is enduring
 
Why should the width and height be reduced by 1 pixel ( and not say 2, ... )?

Why should the Z-order be set?

Making the control flat didn't help, its still offset by the width of the focus rectangle on both sides ( actually this shouldn't have helped any way - as far as I know the 3-D effect is obtained merely by making pairs of borders different in color ).

Turning off the focus rectangle also didn't help, its still offset to the same extent ( bug? maybe that 1 pixel if fsr the f. rectangle? but it looks much fatter than the cell border which is always 3 pxels thick - Right? ).

I'm sure removing the border also shouldn't help, for borders are on the inside of windows - right?

PS. I wish somebody would point me out to the place in MSDN where all this stuff about borders is declared frankly.
 
The z-order is set to ensure that the floating text box is always on top of the grid. My text box has no border and is flat. With the text box positioned you should not be able to distinguish it from a cell.

I have my grid selection mode set to free and no focus rectangle. I use the textbox to disp[lay focus (usually by changing the backcolor of the text box.

The text in the text box does not line up exactly with the text in the grid. I have decided to live with this and did not look into exactly why.

Have you looked at faq222-3262?

zemp
 
Removing the GRID's border is resulting in the text box lining up exactly with the cells ( with or without border and flat or 3-D ) so it seems that the developer's have forgotten to allow correctly for it!

I have decided to retain the single line border for consistency of appearance as I also have a DataCombo in the grid for editing other data and *that* always has a single border. However a new problem has cropped up - the text-box refuses to be narrowed sufficiently to fit into the row! Is there a minimum height for text-boxes? If so how to work around it?
 
I have never had a problem with the adjusting the text box height. But it might be related to the font being used.

I had a similar problem with the Combo box and resolved it with an API call in thread222-797395. Something similar may help you out.

zemp
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top