[Last Call] Learn how to a build a cloud-first strategyRegister Now

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 180
  • Last Modified:

Listbox of Combo Boxes

Experts,

Is there a way to create a listbox where each item is a combobox in Visual Basic 6?
0
NigelRocks
Asked:
NigelRocks
  • 2
2 Solutions
 
VBClassicGuyCommented:
Not unless you're a magician. But I have done something similar before with a sneaky workaround.
First create a subroutine that takes the mouse's x and y locations as parameters. Feed it these parameters with the lisbox's MouseDown event. In the new subroutine, you can calculate the row (and the x, y position) being clicked on, and move an invisible ComboBox (sized just right) on top of that row. Then fill the ComboBox as desired, and then make it visible. Once a selection has been made, you can make the ComboBox invisible again. Play around with this and I'm sure you'll come up with something that looks half decent.
0
 
NigelRocksAuthor Commented:
How about a grid where one of the columns contains a combo box?  Is that possible?
0
 
VBClassicGuyCommented:
Yes it is. My "something similar" I did was to move an invisible TextBox on top of the clicked cell of a MSFlexGrid. It gave it an "Excel-like" functionality. And calculating where to place the TextBox (or in your case, a ComboBox) is MUCH easier with a grid. The cell height and width are properties you can use to size the ComboBox.
With the FlexGrid's MouseUp event (which gives x and y values), I can use these routines:
Function FlexClickedCol%(fg As MSFlexGrid, x!)
   Rem *** Account for scrolled FlexGrid ***
   For c% = 0 To fg.LeftCol - 1
      pos! = pos! + fg.ColWidth(c%)
   Next c%
   pos! = pos! + x!
   Rem *** Calc entire width **
   For c% = 0 To fg.Cols - 1
      w! = w! + fg.ColWidth(c%)
   Next c%
   Rem *** Find cursor position ***
   For c% = fg.Cols - 1 To 0 Step -1
      w! = w! - fg.ColWidth(c%)
      If pos! >= w! Then
         cx% = c%
         Exit For
      End If
   Next c%
   FlexClickedCol% = cx%
End Function

Function FlexClickedRow&(fg As MSFlexGrid, y!)
   If fg.Rows > 2 Then
      Rem *** Get height of header and invisible second row ***
      hdr! = fg.RowHeight(0) + fg.RowHeight(1)
      If y! <= hdr! Then
         rx& = 1
      Else
         pos! = hdr!
         Rem *** Account for scrolled FlexGrid ***
         For r& = 2 To fg.TopRow - 1
            pos! = pos! + fg.RowHeight(r&)
         Next r&
         pos! = pos! + y!
         Rem *** Calc entire height **
         h! = hdr!
         For r& = 2 To fg.Rows - 1
            h! = h! + fg.RowHeight(r&)
         Next r&
         Rem *** Find cursor position ***
         For r& = fg.Rows - 1 To 2 Step -1
            h! = h! - fg.RowHeight(r&)
            If pos! >= h! Then
               rx& = r&
               Exit For
            End If
         Next r&
      End If
   Else
      rx& = 0
   End If
   FlexClickedRow& = rx& - 1
End Function
Notice in the above routine that I use an invisible (well, almost...15 twips height) row right after the header row. Don't ask, long story. Anyway, you can take that part out of the hdr! value calculation.
0

Featured Post

VIDEO: THE CONCERTO CLOUD FOR HEALTHCARE

Modern healthcare requires a modern cloud. View this brief video to understand how the Concerto Cloud for Healthcare can help your organization.

  • 2
Tackle projects and never again get stuck behind a technical roadblock.
Join Now