• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 262
  • Last Modified:

Datagrid button

How do I associate a combobox with a button in a datagrid cell and then populate it?
  • 2
1 Solution
rdolivawAuthor Commented:
Edited text of question.
There is no built in drop down box within the dbgrid.  After you have set the button to be visible, you have to put some code behind the button click event to show your own list.  Below is a quick example.  This is pretty basic, and you will have to play with certain events to get it to work exactly like you want.  Hope this help.

Create a form with a data control, list box, and a dbgrid.  Set the lists and data controls visible poperty to false.  Add some data to the list control.

*******BEGIN CODE**********
Option Explicit
Dim intColIdx As Integer 'This will contain the index for the current cell in the dbgrid
Dim blnListShow As Boolean 'is the list showing or not

Private Sub DBGrid1_ButtonClick(ByVal ColIndex As Integer)
    Dim intTop As Integer
    intColIdx = ColIndex
    If blnListShow = False Then 'if the list is not showing then...
        blnListShow = True
        List1.Left = DBGrid1.Columns(ColIndex).Left + 360
        intTop = DBGrid1.Top + (DBGrid1.RowHeight * (DBGrid1.Row + 2))
        List1.Top = intTop
        List1.Width = DBGrid1.Columns(ColIndex).Width + 15
        List1.Visible = True
    Else 'if the list is show, hide it
        blnListShow = False
        List1.Visible = False
    End If
End Sub

Private Sub Form_Load()
blnListShow = False 'initialize
End Sub

Private Sub List1_Click()
    DBGrid1.Columns(intColIdx).Text = List1.Text 'set the value of the dbgrid
    List1.Visible = False 'hide the list
End Sub

Private Sub List1_LostFocus()
    blnListShow = False
    List1.Visible = False
End Sub
*********END CODE***********************

rdolivawAuthor Commented:
Thanks a bunch!  This is much clearer than the other responses to similar questions in the archive.  I think this'll work.

R. Daneel

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

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