Strange behaviour in MSHFlexgrid celltop property

yronnen
yronnen used Ask the Experts™
on
I'm writing a VB6 application that involves an in-cell editing of a MSHFlexgrid control using comboboxes and text boxes.

In order to set the position of the combo boxes, I use the following code:

cmbGlasses(I).Move fgGlassSub.Left + fgGlassSub.CellLeft, _
                              fgGlassSub.Top + fgGlassSub.CellTop, _
                              fgGlassSub.CellWidth - 8


It should be working, but instead I get a strange behaviour:
The grid is hidden and a I click on a button to see it. When it opens for the first time, the moment I click on a row, it opens the combo box exactly at the next row! If there is only one row, it will show the combo box on the an "empty" background of the MSHFlexgrid.
But the most strange this is that the moment I have enough rows in the grid to show a scroll it begins to work fine, even if I delete rows or reloads the grid with not enough rows to show a scroll.

The grid is inside a frame on the form.

Any ideas for this strange behaviour?

TIA
Comment
Watch Question

Do more with

Expert Office
EXPERT OFFICE® is a registered trademark of EXPERTS EXCHANGE®

Commented:
Please post the full code. The code you have written above is absolutely correct. The problem seems to be somewhere else. You can however, optimize the above code like this:
Hi yronnen,
 
     Try in this way by adding the control to MSHFlexgrid by mshflexgrid.controls.Add()

          Then it would be more flexible and probably you would get into a solution. Also you need not worry about the left and top of the grid, as because once the control is added to the grid, the acts as a small form and the control can only move within the grid, so the left and top of the grid is 0, 0 for the control.

If this dosen't work, Please post the full code.
Cheers
Nazer
 

Author

Commented:
The full code is a monster....I can't send it.

Sethi: your answer does not include the code.
Should you be charging more for IT Services?

Do you wonder if your IT business is truly profitable or if you should raise your prices? Learn how to calculate your overhead burden using our free interactive tool and use it to determine the right price for your IT services. Start calculating Now!

Commented:
Someone else was having the problem that reading the CellTop property in the Scroll event procedure of a MSFlemGrid when either the first or last row was selected stopped the scrolling from working properly!

These controls are just screwy, they lack basic functionality and are just designed to make you cry.  If you're doing a major project (or you just want to hold onto your sanity a bit longer) I might recommend using a half decent third-party grid control.  We used the Janus grid a few years back and while it had some daft bugs, it was nothing like as painful as the MSFlemGrids.  There might be better ones out now (there's bound to be other rubbish as well).

Anyway, the work-around I suggested to that other poor sole was to add up the RowHeights from the TopRow to Row - 1 (or something like that) to get the CellTop.  Fixed their problem (what a mess though!) - dunno if it will help you.

Hmmm... "The full code is a monster"... when using the MSHFlemGrid, what a suprise.

Commented:
My posting the code, I only mean that portion of the code where you are moving this combo. Even if it is a huge code post the relevant parts to see where the problem lies.

Commented:
Option Explicit

Private Sub Form_Load()
    With Me.MSFlexGrid1
        .Rows = 10
        .Cols = 5
        Text1.Visible = False
    End With
End Sub

Private Sub MSFlexGrid1_Click()
    With MSFlexGrid1
        .Row = .MouseRow
        .Col = .MouseCol
        Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
        Text1.Visible = True
    End With
End Sub
Commented:
make sure that you have created the textbox and/or combobox INSIDE the frame itself, not on the form.  If you are not sure then do...

set text1.container = frame1


code again...add a frame, inside the frame as MSFlexgrid and a textbox.  paste this code into the form....

Option Explicit

Private Sub Form_Load()
    Dim i As Long
    Dim j As Long
   
    With Me.MSFlexGrid1
        .Rows = 10
        .Cols = 5
        Text1.Visible = False
        For i = 0 To .Rows - 1
            For j = 0 To .Cols - 1
                .TextMatrix(i, j) = "Row " & i & ": Col " & j
            Next j
        Next i
        .ColWidth(-1) = 1500
    End With
   
End Sub

Private Sub MSFlexGrid1_Click()
    With MSFlexGrid1
        If (.MouseRow < 0 Or .MouseCol < 0) Then
            Text1.Visible = False
            Exit Sub
        End If
        .Row = .MouseRow
        .Col = .MouseCol
        Text1.Move .Left + .CellLeft, .Top + .CellTop, .CellWidth, .CellHeight
        Text1.Text = .Text
        Text1.SelStart = 0
        Text1.SelLength = Len(Text1.Text)
        Text1.Visible = True
        Text1.SetFocus
    End With
End Sub

Private Sub Text1_KeyPress(KeyAscii As Integer)
    If (KeyAscii = vbKeyEscape) Then
        Text1.Visible = False
    ElseIf (KeyAscii = vbKeyReturn) Then
        MSFlexGrid1.Text = Text1.Text
        Text1.Visible = False
    End If
End Sub
Author of the Year 2009

Commented:
Moderator, my recommended disposition is:

    Accept supunr's comment(s) as an answer.

DanRollins -- EE database cleanup volunteer

Do more with

Expert Office
Submit tech questions to Ask the Experts™ at any time to receive solutions, advice, and new ideas from leading industry professionals.

Start 7-Day Free Trial