Solved

DBGrid Control

Posted on 1997-11-19
9
621 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
[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
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
MS Dynamics Made Instantly Simpler

Make Your Microsoft Dynamics Investment Count  & Drastically Decrease Training Time by Providing Intuitive Step-By-Step WalkThru Tutorials.

 
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

[Webinar] Learn How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

The debugging module of the VB 6 IDE can be accessed by way of the Debug menu item. That menu item can normally be found in the IDE's main menu line as shown in this picture.   There is also a companion Debug Toolbar that looks like the followin…
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 …
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…
Suggested Courses
Course of the Month4 days, 6 hours left to enroll

630 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