Solved

Creating DBGRID and COMBO

Posted on 2000-03-22
4
289 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

PeopleSoft Has Never Been Easier

PeopleSoft Adoption Made Smooth & Simple!

On-The-Job Training Is made Intuitive & Easy With WalkMe's On-Screen Guidance Tool.  Claim Your Free WalkMe Account Now

Question has a verified solution.

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

Introduction While answering a recent question about filtering a custom class collection, I realized that this could be accomplished with very little code by using the ScriptControl (SC) library.  This article will introduce you to the SC library a…
Since upgrading to Office 2013 or higher installing the Smart Indenter addin will fail. This article will explain how to install it so it will work regardless of the Office version installed.
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…
This lesson covers basic error handling code in Microsoft Excel using VBA. This is the first lesson in a 3-part series that uses code to loop through an Excel spreadsheet in VBA and then fix errors, taking advantage of error handling code. This l…

733 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