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
Solved

DBGrid Control

Posted on 1997-11-19
9
618 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
Announcing the Most Valuable Experts of 2016

MVEs are more concerned with the satisfaction of those they help than with the considerable points they can earn. They are the types of people you feel privileged to call colleagues. Join us in honoring this amazing group of Experts.

 
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

Free Tool: Subnet Calculator

The subnet calculator helps you design networks by taking an IP address and network mask and returning information such as network, broadcast address, and host range.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

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

Suggested Solutions

Have you ever wanted to restrict the users input in a textbox to numbers, and while doing that make sure that they can't 'cheat' by pasting in non-numeric text? Of course you can do that with code you write yourself but it's tedious and error-prone …
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 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…
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…

856 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