?
Solved

Creating DBGRID and COMBO

Posted on 2000-03-22
4
Medium Priority
?
299 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

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

Article by: Martin
Here are a few simple, working, games that you can use as-is or as the basis for your own games. Tic-Tac-Toe This is one of the simplest of all games.   The game allows for a choice of who goes first and keeps track of the number of wins for…
You can of course define an array to hold data that is of a particular type like an array of Strings to hold customer names or an array of Doubles to hold customer sales, but what do you do if you want to coordinate that data? This article describes…
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…
Suggested Courses
Course of the Month14 days, 10 hours left to enroll

771 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