vb6comboboxmsflexgrid

Call msflexgrid click event in vb6


I've got to call the click event for an MsFlexGrid object.

Private Sub MSFlexGridboxcodelist_Click()
box_code = Trim(Me.MSFlexGridboxcodelist.TextMatrix(Me.MSFlexGridboxcodelist.RowSel, 1))
box_type = Trim(Me.MSFlexGridboxcodelist.TextMatrix(Me.MSFlexGridboxcodelist.RowSel, 7))
Me.Txtpack_weight.text = Trim(Me.MSFlexGridboxcodelist.TextMatrix(Me.MSFlexGridboxcodelist.RowSel, 5))

Dim x As Integer
For x = 0 To Me.Combobox_type.ListCount - 1
    If Me.Combobox_type.List(x) = box_type Then
        Me.Combobox_type.ListIndex = x
        Exit For
    End If
Next
End Sub

The problem is when I actually click on the flexgrid, this part works as it should:

Me.Combobox_type.ListIndex = x

But when I do this:

Me.MSFlexGridboxcodelist.row = i
Me.MSFlexGridboxcodelist.TopRow = i
Me.MSFlexGridboxcodelist.RowSel = i

For x = 0 To Me.MSFlexGridboxcodelist.cols - 1
    Me.MSFlexGridboxcodelist.ColSel = x
Next x
Call MSFlexGridboxcodelist_Click

The needed item in the combobox is not selected. So I guess the is a difference between clicking on something and calling the click event, but I have no clue what. I know I could just set the text of the combobox to whatever I want, but users shouldn't be allowed do it, so I set it's style attribute to Dropdown list.

Could you guys give me tip?

Thanks in advance.


Solution

  • Clicking via the mouse will call multiple events (some of which might not be exposed in VB6). The click event code will be ran as part of one of these events. Calling Grid.Click() does NOT simulate a mouse click.

    Not sure what the second piece of code is trying to do? Setting ColSel will select the columns between .Col and .ColSel, so that loop will set an ever increasing selection size. In fact it will select every column, so why bother?

    Why not change the click event to loop through the columns retrieving the text?