|
-
Apr 24th, 2007, 09:57 AM
#1
Thread Starter
Hyperactive Member
[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.
-
Apr 24th, 2007, 10:04 AM
#2
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
-
Apr 24th, 2007, 10:39 AM
#3
Thread Starter
Hyperactive Member
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.
-
Apr 24th, 2007, 10:41 AM
#4
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.
-
Apr 24th, 2007, 11:10 AM
#5
Thread Starter
Hyperactive Member
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
-
Apr 24th, 2007, 11:14 AM
#6
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
And you just put Dim_Combo in the grid's click event?
-
Apr 24th, 2007, 11:26 AM
#7
Thread Starter
Hyperactive Member
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
-
Apr 24th, 2007, 11:28 AM
#8
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
What is the "little error"?
-
Apr 24th, 2007, 11:38 AM
#9
Thread Starter
Hyperactive Member
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?
-
Apr 24th, 2007, 11:39 AM
#10
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.
-
Apr 24th, 2007, 01:07 PM
#11
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.
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 24th, 2007, 01:14 PM
#12
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
Are you talking about what I posted fails if you scroll?
-
Apr 24th, 2007, 04:38 PM
#13
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
The most difficult part of developing a program is understanding the problem.
The second most difficult part is deciding how you're going to solve the problem.
Actually writing the program (translating your solution into some computer language) is the easiest part.
Please indent your code and use [HIGHLIGHT="VB"] [/HIGHLIGHT] tags around it to make it easier to read.
Please Help Us To Save Ana
-
Apr 24th, 2007, 05:39 PM
#14
Thread Starter
Hyperactive Member
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?
-
Apr 24th, 2007, 06:33 PM
#15
Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid
 Originally Posted by Al42
No, what RS_Arm posted.
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....
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|