[RESOLVED] Popup ComboBox in a MSHFlexgrid
Hi. I need to popup a combobox in front of a cell (MSHFlexgrid) or on mouse position.
The trigger: mouse right-button.
I've got this code, but it sucks:
Code:
Private Sub GridEmissaoFact_MouseUp(Button As Integer, Shift As Integer, x As Single, y As Single)
'...
Me.ComboSerie.Left = x - (Me.ComboSerie.Width / 2)
Me.ComboSerie.Top = y + (Me.ComboSerie.Height)
'...
Need help.
Thanks.:)
Re: Popup ComboBox in a MSHFlexgrid
Try this.
vb Code:
Private Sub Form_Load()
Dim i As Long
' Prepare combo
With Combo1
' Hide combo
.Visible = False
.AddItem "line 1"
.AddItem "line 2"
.AddItem "line 3"
End With
' Prepare grid
With MSFlexGrid1
.Top = 0
.Width = Me.Width
.Height = Me.Height
.Left = 0
For i = 0 To MSFlexGrid1.Cols - 1
.RowHeight(i) = Combo1.Height
Next
End With
End Sub
'Put SetUpCombo In the Grids Click Event
Private Sub SetupCombo()
' Setup the combobox by positioning and sizing it over the
' current flexgrid cell
Dim sngL As Single
Dim sngT As Single
Dim sngW As Single
Dim sngH As Single
With MSFlexGrid1.Container
sngL = .ScaleX(MSFlexGrid1.CellLeft, vbTwips, .ScaleMode)
sngT = .ScaleY(MSFlexGrid1.CellTop, vbTwips, .ScaleMode)
sngW = .ScaleX(MSFlexGrid1.CellWidth, vbTwips, .ScaleMode)
sngH = .ScaleY(MSFlexGrid1.CellHeight, vbTwips, .ScaleMode)
End With
With Combo1
.Move MSFlexGrid1.Left + sngL, MSFlexGrid1.Top + sngT, sngW
.Visible = True
.SetFocus
End With
End Sub
Re: Popup ComboBox in a MSHFlexgrid
Thank you, but in MSHFlexGrid (Hierarchical) I can't use ".ScaleX" (lines 35 to 38).
I got this error: Run-time error 438. Object doesn't support this property or method.
Re: Popup ComboBox in a MSHFlexgrid
I actually switched grids for this project because of the same problem.
For an MSHFlexGrid, I don't know of a workaround except perhaps what you have now.
Re: Popup ComboBox in a MSHFlexgrid
I've done this. It works pretty nice:
Code:
Private sub Dim_Combo ()
Dim oLeft As Single
Dim oTop As Single
oLeft = Me.MSHFlexgrid1.ColWidth(0) + Me.MSHFlexgrid1.ColWidth(1) + Me.MSHFlexgrid1.Left
oTop = Me.MSHFlexgrid1.Top + (Me.MSHFlexgrid1.CellHeight * Me.MSHFlexgrid1.RowSel)
With Me.Combo
.Width = Me.MSHFlexgrid1.ColWidth(2)
.Move oLeft, oTop
.Visible = True
.SetFocus
End With
end sub
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
And you just put Dim_Combo in the grid's click event?
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Yes.On form load, the combo is set to invisible.
So, when the event is triggered ,It will pop up the combo in front of the MsHFlexgrid.
Meanwhile, I've detected a little "error" on my code.
Here it goes the updated version:
Code:
Private sub Dim_Combo ()
Dim oLeft As Single
Dim oTop As Single
oLeft = Me.MSHFlexgrid1.ColWidth(0) + Me.MSHFlexgrid1.ColWidth(1) + Me.MSHFlexgrid1.Left
oTop = Me.MSHFlexgrid1.Top + ((Me.MSHFlexgrid1.CellHeight+15) * Me.MSHFlexgrid1.RowSel) '15twips = 1pixel (it corresponds to the line separator)
With Me.Combo
.Width = Me.MSHFlexgrid1.ColWidth(2)
.Move oLeft, oTop
.Visible = True
.SetFocus
End With
end sub
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
What is the "little error"?
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
It is not a error. If you've got many rows, the combobox it would not be quite exactly on the top the selected cell, due to the line that separates rows. So, I've incremented 15twips(=1pixel).
Got it?;)
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Yes, I do understand, and as a matter of fact, after I read your post I remembered that I ran into something very similar on my project. :)
Anyway, it is working and that is all that matters.
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
I don't know about MSHFlexGrid, but using RS_Arm's code on a MSFlexGrid fails if you scroll the grid - oTop calculates for the row number, not the row position. It should be
Code:
oTop = MSFlexGrid1.Top + MSFlexGrid1.RowPos(MSFlexGrid1.RowSel)
to allow for scrolling. (In the scroll event, you should also check for .RowIsVisible(.RowSel) and, if the combobox is visible and the row isn't, make the combobox invisible.)
And thank you for some nice code.
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Are you talking about what I posted fails if you scroll?
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Ok. You are right AI42. Thank's.
But you can't use "MSFlexGrid1.RowPos(MSFlexGrid1.RowSel)" in MSHFlexgrid.
I'll try fix that situation, maybe counting the rows that are visible and locating the selected row. What do you think? Would you have another idea?
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Quote:
Originally Posted by Al42
No, what RS_Arm posted.
:lol: You have no idea how glad I am to read this.
That piece of code that I posted was "cleaned" up from a commerical project I did a couple of years ago and has been purchased by a "few" of our customers.
No one had ever reported this, but that didn't mean it didn't exist.
*wipes brow* phew....:D