Results 1 to 15 of 15

Thread: [RESOLVED] Popup ComboBox in a MSHFlexgrid

  1. #1

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    Resolved [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.

  2. #2
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: Popup ComboBox in a MSHFlexgrid

    Try this.
    vb Code:
    1. Private Sub Form_Load()
    2. Dim i As Long
    3.     ' Prepare combo
    4.     With Combo1
    5.         ' Hide combo
    6.         .Visible = False
    7.         .AddItem "line 1"
    8.         .AddItem "line 2"
    9.         .AddItem "line 3"
    10.     End With
    11.    
    12.     ' Prepare grid
    13.     With MSFlexGrid1
    14.         .Top = 0
    15.         .Width = Me.Width
    16.         .Height = Me.Height
    17.         .Left = 0
    18.         For i = 0 To MSFlexGrid1.Cols - 1
    19.             .RowHeight(i) = Combo1.Height
    20.         Next
    21.     End With
    22. End Sub
    23.  
    24. 'Put SetUpCombo In the Grids Click Event
    25. Private Sub SetupCombo()
    26. ' Setup the combobox by positioning and sizing it over the
    27. ' current flexgrid cell
    28.  
    29. Dim sngL As Single
    30. Dim sngT As Single
    31. Dim sngW As Single
    32. Dim sngH As Single
    33.  
    34.     With MSFlexGrid1.Container
    35.         sngL = .ScaleX(MSFlexGrid1.CellLeft, vbTwips, .ScaleMode)
    36.         sngT = .ScaleY(MSFlexGrid1.CellTop, vbTwips, .ScaleMode)
    37.         sngW = .ScaleX(MSFlexGrid1.CellWidth, vbTwips, .ScaleMode)
    38.         sngH = .ScaleY(MSFlexGrid1.CellHeight, vbTwips, .ScaleMode)
    39.     End With
    40.  
    41.     With Combo1
    42.         .Move MSFlexGrid1.Left + sngL, MSFlexGrid1.Top + sngT, sngW
    43.         .Visible = True
    44.         .SetFocus
    45.     End With
    46.  
    47. End Sub

  3. #3

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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.

  4. #4
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  5. #5

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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

  6. #6
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid

    And you just put Dim_Combo in the grid's click event?

  7. #7

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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

  8. #8
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid

    What is the "little error"?

  9. #9

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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?

  10. #10
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    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.

  11. #11
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    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

  12. #12
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid

    Are you talking about what I posted fails if you scroll?

  13. #13
    PowerPoster
    Join Date
    Feb 2006
    Location
    East of NYC, USA
    Posts
    5,691

    Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid

    No, what RS_Arm posted.
    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

  14. #14

    Thread Starter
    Hyperactive Member RS_Arm's Avatar
    Join Date
    Mar 2007
    Location
    Planet Earth
    Posts
    282

    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?

  15. #15
    I'm about to be a PowerPoster! Hack's Avatar
    Join Date
    Aug 2001
    Location
    Searching for mendhak
    Posts
    58,333

    Re: [RESOLVED] Popup ComboBox in a MSHFlexgrid

    Quote 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
  •  



Click Here to Expand Forum to Full Width