0

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.

Joe88
  • 441
  • 1
  • 5
  • 15

1 Answers1

1

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?

cjb110
  • 1,310
  • 14
  • 30
  • Yeah I know that col selection isn't the best. But that's not the question here :) My problem is that I search for the value of the last column of the grid in a combobox and when it's found I want to select it. I've got the value, it would be enough since I can work with that, but I also want the combobox to show it to make sure users are not confused and they can see that the code did it's job. – Joe88 Sep 12 '12 at 12:35
  • If you have found the value, don't you then have the row and col number? And couldn't you then set .row = x, .rowsel = x, .col = y and .colsel = y. i.e. highlight that one cell? – cjb110 Sep 14 '12 at 07:14
  • oh, just found something mentioning needing to use .setfocus as well. i.e. you can't select without the control having focus...which kinda makes sense. – cjb110 Sep 14 '12 at 07:19