Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Creating DBGRID and COMBO

Posted on 2000-03-22
4
Medium Priority
?
304 Views
Last Modified: 2013-12-25
Dear Expert;
  DBGRID in VB6 , Assume that I have 3 fields(Prod_Code, Prod_Desc, Prod_Pr)
In first field , Can I choose product code from all product code Master file?

(The first field of DBGRID is look like combo box to show all product code)

Can I do? Please answer me...
0
Comment
Question by:u3520384
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 4

Expert Comment

by:CraigLazar
ID: 2645827
Hi
please can u give us a little more information in what u are trying to do.
But from what i can gather, go into the custom properties of the grid and in Column(0) which should be your Prod_Code, there is a check box under layout, pick your column and check the button command. When you run your app again u will notice similar to a drop down list box. You will then have to play around but i am guessing use the grids button event and populate the list from there, that might do it for u


hope this helps

:)

Craig
0
 

Accepted Solution

by:
kimster earned 800 total points
ID: 2646956
I think I may want to use the DBGrid with a combo in the future too...
So I did a sample prog to see how it works

Create a new project with 2 data controls, a dbgrid and a dblist.

Data1 should point to your general database table
Data2 should point read-only to the table that holds all the valid Prod_Codes

Make Data1 the Datasource of the DBGrid
Make Data2 the RowSource of DBList1 and enter "Prod_Code" under ListField.

Now here is some code!

Private Sub DBGrid1_BeforeColEdit(ByVal ColIndex As Integer, ByVal KeyAscii As Integer, Cancel As Integer)
'Before ColEdit is called before the grid enters into
'edit mode. Here is the place to separate the different
'types of editing, for the Prod_Code the downdown list,
'and for the other fields regular editing.

If DBGrid1.Columns(ColIndex).DataField = "Prod_Desc" Or _
DBGrid1.Columns(ColIndex).DataField = "Prod_Pr" Then
    'Regular editing
    If KeyAscii <> 0 Then Exit Sub
   
    'Else the downdown list
    Cancel = True
    DBGrid1_ButtonClick (ColIndex)
End If
   
End Sub

Private Sub DBGrid1_ButtonClick(ByVal ColIndex As Integer)

Dim datagridcol As Column
Set datagridcol = DBGrid1.Columns(ColIndex)

DBList1.Left = DBGrid1.Left + datagridcol.Left + datagridcol.Width
DBList1.Top = DBGrid1.Top + DBGrid1.RowTop(DBGrid1.Row)
DBList1.Visible = True
DBList1.ZOrder 0
DBList1.SetFocus

End Sub

Private Sub DBGrid1_Scroll(Cancel As Integer)
'Hide the list when scrolling
DBList1.Visible = False
End Sub

Private Sub Form_Load()
DBList1.Visible = False
'Place a button in the Prod_Code column
DBGrid1.Columns("Prod_Code").Button = True
End Sub

Private Sub DBList1_DblClick()
'When an item is selected in List1, copy its index
'to the proper column in DBGrid1, then hide List1 again.
DBGrid1.Columns("Prod_Code").Text = DBList1.Text
DBList1.Visible = False
End Sub

Private Sub DBList1_LostFocus()
'Hide the list when it looses focus
DBList1.Visible = False
End Sub


Good luck! =)
0
 

Author Comment

by:u3520384
ID: 2716946
Dear Expert...
 
 I have VB6 Professional... I have no DBGRID32.OCX...
How to load it...
0
 

Expert Comment

by:kimster
ID: 2717953
You can find the DBGRID32.OCX under Common\Tools\Vb\Controls

You will also find the file to register the control there...
0

Featured Post

Important Lessons on Recovering from Petya

In their most recent webinar, Skyport Systems explores ways to isolate and protect critical databases to keep the core of your company safe from harm.

Question has a verified solution.

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

There are many ways to remove duplicate entries in an SQL or Access database. Most make you temporarily insert an ID field, make a temp table and copy data back and forth, and/or are slow. Here is an easy way in VB6 using ADO to remove duplicate row…
This article describes how to use a set of graphical playing cards to create a Draw Poker game in Excel or VB6.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Outlook using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Microsoft Outlook. Using automation, an Access applic…
Suggested Courses

618 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