Solved

DBGrid Control

Posted on 1997-11-19
9
616 Views
Last Modified: 2010-05-18
VB5 Gives the ability to provide a build-in combobox within a DBGrid control. I'ld like to use that function but there is very few information available about it. Is there someone who can help me with writing an example code ?
0
Comment
Question by:ndb
9 Comments
 
LVL 6

Expert Comment

by:anthonyc
ID: 1441470
What you need to do is create some "valueitems" for a column.  to do this, do the following:

dim viItem  as valueitem


With .Columns(0) 'works on the first column
            .Valueitems.presentation = dbgComboBox

            .ValueItems.Clear
            .ValueItems.CycleOnClick = True
            .ValueItems.Translate = True
            .ValueItems.Validate = True
           
            'add value items
            viItem.DisplayValue = "Value"
            viItem.Value = True
            .ValueItems.Add viItem
           
            viItem.DisplayValue = "Text"
            viItem.Value = False
            .ValueItems.Add viItem  'you can add as many as ya want
End With

0
 
LVL 6

Expert Comment

by:anthonyc
ID: 1441471
I forgot to put the dbgrid1 in the with statement.

The with statement should read

with dbgrid1.columns(0)


sorry about that
0
 
LVL 1

Author Comment

by:ndb
ID: 1441472
Can I link the valueitems to another table with data ?
0
Ransomware-A Revenue Bonanza for Service Providers

Ransomware – malware that gets on your customers’ computers, encrypts their data, and extorts a hefty ransom for the decryption keys – is a surging new threat.  The purpose of this eBook is to educate the reader about ransomware attacks.

 
LVL 6

Expert Comment

by:anthonyc
ID: 1441473
well you can:

dim rsData as recordset
dim viItem as new valueitem

set rsData = db.openrecordset("select keyval, displayval from table1", dbOpenSnapshot)

with dbgrid1.columns(0)
   do until rsdata.eof
     viItem.value = rsData!keyval
     viItem.displayvalue = rsData!displayval
     .valueitems.add viItem
     rsData.movenext
   loop
end with


but it cant be done directly
   
0
 
LVL 1

Author Comment

by:ndb
ID: 1441474
What kind of DBGrid are you using. I don't find the property ValueItems.
0
 
LVL 1

Author Comment

by:ndb
ID: 1441475
I don't have these properties you are talking about.
0
 
LVL 3

Accepted Solution

by:
Matvey earned 100 total points
ID: 1441476
Actually I had the same problem.
My solution was to attach a ListBox to the event ButtonClick
of the DBGrid. But DBGrid's button is ugly, and you
shouldn't use it. You should put a ComboBox in the place
of the cell any time it gets focus.

Good luck !
                Matvey
0
 
LVL 1

Author Comment

by:ndb
ID: 1441477
It seems to be the only solution.
0
 

Expert Comment

by:NAVemail
ID: 23099927
I tried the solution and it does not work for me.
I have the TDBGrid and I wanted to make a column from text to comboBox.
The column it shows the combobox control but the items are not displayed when I click on the arrow.
This is my code:
            With grd.Columns(12)  'works on the first column
                .ValueItems.Presentation = dbgComboBox

                .ValueItems.Clear
                .ValueItems.CycleOnClick = True
                .ValueItems.Translate = True
                .ValueItems.Validate = True
           
                'add value items
                viItem.DisplayValue = "05 - Reason 91"
                viItem.Value = True
                .ValueItems.Add viItem
           
                viItem.DisplayValue = "07 - Reason 48"
                viItem.Value = True
                .ValueItems.Add viItem
               
                viItem.DisplayValue = "09 - Reason 8"
                viItem.Value = True
                .ValueItems.Add viItem
           
                viItem.DisplayValue = "08 - Reason 24"
                viItem.Value = True
                .ValueItems.Add viItem
            End With
Non of the option are shown.

could someone help me please?

Thank you
0

Featured Post

Netscaler Common Configuration How To guides

If you use NetScaler you will want to see these guides. The NetScaler How To Guides show administrators how to get NetScaler up and configured by providing instructions for common scenarios and some not so common ones.

Question has a verified solution.

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

Suggested Solutions

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.
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
Get people started with the utilization of class modules. Class modules can be a powerful tool in Microsoft Access. They allow you to create self-contained objects that encapsulate functionality. They can easily hide the complexity of a process from…
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…

803 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