Solved

Creating DBGRID and COMBO

Posted on 2000-03-22
4
266 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
  • 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 200 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

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

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

Suggested Solutions

When trying to find the cause of a problem in VBA or VB6 it's often valuable to know what procedures were executed prior to the error. You can use the Call Stack for that but it is often inadequate because it may show procedures you aren't intereste…
I was working on a PowerPoint add-in the other day and a client asked me "can you implement a feature which processes a chart when it's pasted into a slide from another deck?". It got me wondering how to hook into built-in ribbon events in Office.
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…
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…

929 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

Need Help in Real-Time?

Connect with top rated Experts

12 Experts available now in Live!

Get 1:1 Help Now