So basically all I have to do then is pass a reference to the listbox, then have that listbox appear for the column when the button is clicked?
Sounds too easy to be true! I will try this and get back to you. Thank you.
Main Topics
Browse All TopicsI have added to button to a cell in a datagrid in a vb6 program.
I would like to a drop down list to the button to return a value of a field from another table and I have no idea of how to do this if possible.
Or how to add a datacombo to a datagrid and have it return a value from a field in another table.
This Question has been solved and asker verified All Experts Exchange premium technology solutions are available to subscription members.
Experts Exchange has been collecting answers to technology questions since 1996…3 million and counting! If you have a question, chances are we already have your answer.
If you can't find the exact answer you're looking for, ask our exclusive community of 50,000 experts. You’ll get a personalized answer from a trusted professional.
Thousands of free tech tips, tricks, how-to’s and tutorials are available in our peer reviewed articles section. See for yourself how smart our experts are, no login required.
Access the answers to your technology questions today.
30-day free trial. Register in 60 seconds.
Members of the expert community talk about why the experience at Experts Exchange is different than what you will find anywhere else.

Try it out and discover for yourself.
30-day free trial. Register in 60 seconds.
Join the community of experts here and help other tech pros by answering question in your area of expertise. You can earn FREE access to all Experts Exchange's premium features and resources.
I can't seem to get the button event to show the listbox..
I have a grid on the form and a listbox.
It shows the button, and it shows the listbox with the correct data from the database..what am I doing wrong here???
--------------------------
Option Explicit
Dim intColIdx As Integer
'This will contain the index for the current cell in the dbgrid
Dim adoPrimaryRS As Recordset
Dim blnListShow As Boolean 'is the list showing or not Dim WithEvents adoPrimaryRS As Recordset
Dim mbChangedByCode As Boolean
Dim mvBookMark As Variant
Dim mbEditFlag As Boolean
Dim mbAddNewFlag As Boolean
Dim mbDataChanged As Boolean
Private Sub Form_Load()
Dim db As Connection
Set db = New Connection
Dim MyColumns As Columns
db.CursorLocation = adUseClient
'db.Open "PROVIDER=MSDataShape;Data
db.Open "PROVIDER=Microsoft.Jet.OL
Set adoPrimaryRS = New Recordset
adoPrimaryRS.Open "SELECT DISTINCT EmployeeID FROM OrderDetails WHERE EmployeeID IS NOT NULL", db, adOpenForwardOnly
'adoprimaryrs.Open "SHAPE {select AllTotals,CitySalesTax,Cou
blnListShow = False 'initialize
'Dim oText As TextBox
'Bind the text boxes to the data provider
'For Each oText In Me.txtFields
'Set oText.DataSource = adoPrimaryRS
' Next
List1.AddItem "" 'add a blank item
Do While Not adoPrimaryRS.EOF 'populate the list box
List1.AddItem adoPrimaryRS!EmployeeID
adoPrimaryRS.MoveNext
Loop
adoPrimaryRS.Close
Set DBgrid1.DataSource = adoPrimaryRS '("ChildCMD").UnderlyingVa
Set MyColumns = DBgrid1.Columns 'create Columns Object
MyColumns.Item(0).Alignmen
MyColumns.Item(0).AllowSiz
MyColumns.Item(0).Locked = True 'don't allow it to be selected
MyColumns.Item(0).Button = True 'display button when selected
MyColumns.Item(0).Button = True
MyColumns.Item(0).Width = 1000 'set column width to 2000 pixels
mbDataChanged = False
End Sub
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(0).Left + 360
intTop = DBgrid1.Top + (DBgrid1.RowHeight * (DBgrid1.Row + 2))
List1.Top = intTop
List1.Width = DBgrid1.Columns(0).Width + 15
List1.Visible = True
List1.SetFocus
Else 'if the list is show, hide it
blnListShow = False
List1.Visible = False
End If
End Sub
Private Sub List1_Click()
'Set adoPrimaryRS = New Recordset
'Set List1.DataSource = adoPrimaryRS
DBgrid1.Columns(intColIdx)
'DBgrid1.Columns(0).Text = List1.Text
Set adoPrimaryRS = New Recordset
Set List1.DataSource = adoPrimaryRS
'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
This is working on my PC:
VERSION 5.00
Object = "{CDE57A40-8B86-11D0-B3C6-
Begin VB.Form frmAssembly
Caption = "Assembly"
ClientHeight = 6540
ClientLeft = 1104
ClientTop = 348
ClientWidth = 9096
KeyPreview = -1 'True
LinkTopic = "Form1"
ScaleHeight = 6540
ScaleWidth = 9096
Begin MSDataGridLib.DataGrid DataGrid1
Height = 3972
Left = 240
TabIndex = 1
Top = 120
Width = 7932
_ExtentX = 13991
_ExtentY = 7006
_Version = 393216
HeadLines = 1
RowHeight = 15
BeginProperty HeadFont {0BE35203-8F91-11CE-9DE3-0
Name = "MS Sans Serif"
Size = 7.8
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
BeginProperty Font {0BE35203-8F91-11CE-9DE3-0
Name = "MS Sans Serif"
Size = 7.8
Charset = 0
Weight = 400
Underline = 0 'False
Italic = 0 'False
Strikethrough = 0 'False
EndProperty
ColumnCount = 2
BeginProperty Column00
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-0
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1033
SubFormatType = 0
EndProperty
EndProperty
BeginProperty Column01
DataField = ""
Caption = ""
BeginProperty DataFormat {6D835690-900B-11D0-9484-0
Type = 0
Format = ""
HaveTrueFalseNull= 0
FirstDayOfWeek = 0
FirstWeekOfYear = 0
LCID = 1033
SubFormatType = 0
EndProperty
EndProperty
SplitCount = 1
BeginProperty Split0
BeginProperty Column00
EndProperty
BeginProperty Column01
EndProperty
EndProperty
End
Begin VB.ListBox List1
Height = 1392
Left = 4680
TabIndex = 0
Top = 4440
Width = 1332
End
End
Attribute VB_Name = "frmAssembly"
Attribute VB_GlobalNameSpace = False
Attribute VB_Creatable = False
Attribute VB_PredeclaredId = True
Attribute VB_Exposed = False
Option Explicit
Private rstData As ADODB.Recordset
Private Sub DataGrid1_BeforeColEdit(By
' BeforeColEdit is called before the grid enters into
' edit mode. You can decide what happens and whether
' standard editing proceeds. This allows you to
' substitute different kinds of editing for the current
' cell, as is done here.
If DataGrid1.Columns(ColIndex
' ' Let the user edit by entering a key.
' If KeyAscii <> 0 Then Exit Sub
' Otherwise, cancel built-in editing and call the
' ButtonClick event to drop down List1.
Cancel = True
Call DataGrid1_ButtonClick(ColI
End If
End Sub
Private Sub DataGrid1_ButtonClick(ByVa
' Assign the Column object to Co because it will be used more than once.
Dim Co As Column
Set Co = DataGrid1.Columns(ColIndex
' Position and drop down List1 at the right edge of the current cell.
If ColIndex = 1 Then
With List1
.Left = DataGrid1.Left + Co.Left
.Top = DataGrid1.Top + DataGrid1.RowTop(DataGrid1
.Width = Co.Width
.Visible = True
.ZOrder 0
.SetFocus
End With
End If
End Sub
Private Sub DataGrid1_Scroll(Cancel As Integer)
List1.Visible = False
End Sub
Private Sub List1_DblClick()
' When an item is selected in List1, copy its index to the
' proper column in DBGrid1, then make List1 invisible.
DataGrid1.Columns("Field2"
List1.Visible = False
DataGrid1.SetFocus
End Sub
Private Sub List1_LostFocus()
' Hide the list if it loses focus.
List1.Visible = False
DataGrid1.SetFocus
End Sub
Private Sub Form_Load()
Set rstData = New ADODB.Recordset
With rstData
.Fields.Append "Field1", adInteger
.Fields.Append "Field2", adVarChar, 20
.Open
.AddNew Array("Field1", "Field2"), Array(1, "T1")
.AddNew Array("Field1", "Field2"), Array(1, "T2")
.AddNew Array("Field1", "Field2"), Array(1, "T3")
.AddNew Array("Field1", "Field2"), Array(1, "T4")
.AddNew Array("Field1", "Field2"), Array(1, "T5")
End With
With DataGrid1
Set .DataSource = rstData
With .Columns(1)
.Button = True
.Width = 1500
End With
End With
With List1
.Visible = False
.AddItem "T1"
.AddItem "T2"
.AddItem "T3"
End With
End Sub
I unlocked it and it still didn't work....
Here is a link to what I am trying to do. There is a small zip file you can download with the database actually in it.
I checked the database and the field EmployeeID is updateable as it is text and can have duplicates...
I have no idea of why this is not working.
http://www.jamiegrossfeld.
One more thing...if you read my initial question again, you clearly can see that I wanted it to attach to a recordset...I did
not simply ask how to get a button to work on a grid which is the code you posted. I wanted to know how to get the values
out of tables.....not just how to put a button on a datagrid.
I asked something a bit more specific than that. Unfortunately, you
did not read the question clearly and your answer would never have solved my problem:
Initial question:
I have added to button to a cell in a datagrid in a vb6 program.
I would like to a drop down list to the button to return a value of a field from another table and I have no idea of how to do this if possible.
Or how to add a datacombo to a datagrid and have it return a value from a field in another table.
Business Accounts
Answer for Membership
by: emoreauPosted on 2004-02-04 at 10:07:43ID: 10273263
Add a ListBox and make its visible property to False.
Left + 360 Width + 15
.Text = List1.Text
'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).
intTop = DBGrid1.Top + (DBGrid1.RowHeight * (DBGrid1.Row +2))
List1.Top = intTop
List1.Width = DBGrid1.Columns(ColIndex).
List1.Visible = True
List1.SetFocus
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)
'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