Solved

Creating DBGRID and COMBO

Posted on 2000-03-22
4
256 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
Comment Utility
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
Comment Utility
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
Comment Utility
Dear Expert...
 
 I have VB6 Professional... I have no DBGRID32.OCX...
How to load it...
0
 

Expert Comment

by:kimster
Comment Utility
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

Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

Join & Write a Comment

Introduction In a recent article (http://www.experts-exchange.com/A_7811-A-Better-Concatenate-Function.html) for the Excel community, I showed an improved version of the Excel Concatenate() function.  While writing that article I realized that no o…
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…
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…
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…

772 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

13 Experts available now in Live!

Get 1:1 Help Now