?
Solved

Combobox in an ADO datagrid

Posted on 2004-11-27
1
Medium Priority
?
615 Views
Last Modified: 2012-06-21
Hello,

I am a VB6 beginner, and I am looking to use an ADO datagrid with a combobox.  Basically I want to put the combobox on the current datagrid cell so that I can update the grid with a selection from the combo.  The problem I have is this:

I can do it OK with a flexgrid, as follows:

Private Sub MSFlexGrid1_MouseDown(Button As Integer, Shift As Integer, x As Single, y As Single)
Combo1.Visible = False
        Combo1.Left = MSFlexGrid1.Left + MSFlexGrid1.CellLeft
        Combo1.Top = MSFlexGrid1.Top + MSFlexGrid1.CellTop
        Combo1.Width = MSFlexGrid1.CellWidth
        Combo1.Visible = True
End Sub

but I want to use a datagrid because a databound flexgrid is only readonly, and I want to be able to update my database table automatically.  This I can do with a datagrid.  But I can find no way of referencing the datagrid cell in the necessary way.  Help!  Is this impossible with a datagrid???

Alternatively, does anyone know a freeware grid with the above capabilities (ie databinding and cell referencing).

Many thanks,
Trimtrom
0
Comment
Question by:trimtrom
1 Comment
 
LVL 70

Accepted Solution

by:
Éric Moreau earned 400 total points
ID: 12686602
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
                  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).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  
0

Featured Post

Vote for the Most Valuable Expert

It’s time to recognize experts that go above and beyond with helpful solutions and engagement on site. Choose from the top experts in the Hall of Fame or on the right rail of your favorite topic page. Look for the blue “Nominate” button on their profile to vote.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
When designing a form there are several BorderStyles to choose from, all of which can be classified as either 'Fixed' or 'Sizable' and I'd guess that 'Fixed Single' or one of the other fixed types is the most popular choice. I assume it's the most p…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…
Show developers how to use a criteria form to limit the data that appears on an Access report. It is a common requirement that users can specify the criteria for a report at runtime. The easiest way to accomplish this is using a criteria form that a…
Suggested Courses
Course of the Month13 days, 15 hours left to enroll

807 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question