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

Button on a DBGrid

Hello everyone,

I have a button placed in a DBGrid. How can I create a DBlist that shows up in the datagrid when the button is clicked.

1 Solution
Éric MoreauSenior .Net ConsultantCommented:
Add a ListBox and make its visible property to False.

'Add this code to the form declaration

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
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

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