Wrox Programmer Forums

Need to download code?

View our list of code downloads.

Go Back   Wrox Programmer Forums > Visual Basic > VB 6 Visual Basic 6 > VB Databases Basics
Password Reminder
| FAQ | Members List | Search | Today's Posts | Mark Forums Read
VB Databases Basics Beginning-level VB coding questions specific to using VB with databases. Issues not specific to database use will be redirected to other forums.
Welcome to the p2p.wrox.com Forums.

You are currently viewing the VB Databases Basics section of the Wrox Programmer to Programmer discussions. This is a community of tens of thousands of software programmers and website developers including Wrox book authors and readers. As a guest, you can read any forum posting. By joining today you can post your own programming questions, respond to other developers’ questions, and eliminate the ads that are displayed to guests. Registration is fast, simple and absolutely free .
DRM-free e-books 300x50
Thread Tools Search this Thread Display Modes
  #1 (permalink)  
Old October 4th, 2006, 10:15 PM
Authorized User
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts
Default How to add a datagridcombobox programmatically ?

Hey whats up guys how is everyone ?

Anyhow I wanted to know how to add a combobox within a DatagridView...not a Datagrid from (VB 2003) .

Ok here is my objective...I want to add a combobox within one of the fields in the Datagridview..not necessarily adding an Extra Field within the Datagridview..but an actual combobox within the grid itself.

So example if I want to pick a state I can just click on the datagridview within the field name "State" and then when I click it the combobox appears and pretty much i can choose a state.

Remember guys I don't need to do this through the IDE...i need to figure out a way on how to insert this combobox within my datagridview.

I know it's crazy ,but it can be done.

Thankyou guys in advance...and just like before if I find a way on how to do it then I will post the code for the community to share.

Take care everyone :)

Reply With Quote
  #2 (permalink)  
Old October 23rd, 2006, 03:08 PM
Authorized User
Join Date: Oct 2005
Location: , , USA.
Posts: 30
Thanks: 0
Thanked 0 Times in 0 Posts

Hey guys whats up its been a while..anyhow this is a bit tricky and I was able to pull it off, so tell me what you guys think, try it out and let me know how it worked for you guys .

Anyhow remember the objective is in case you don't want to do this through the IDE, you can then program a combo box within a datagridview to populate values with what ever you want and then when your use click on a particular area of the grid he/she can use the values given at the box you just define.

Ok bare with me because its a bit tricky...

One thing that got me nuts and hopefully it won't for you guys would be to make sure you have your grid to autogenerate columns to "False"..not in the IDE..but in the code itself.:)

if you don't define this believe me you will get extra columns plus the one you define

so anyhow with that in mind here is the code you can define within your code to make the grid have a nice combobox


(user paid is my variable)

     Dim UserPaid As New DataGridViewComboBoxColumn()
     UserPaid.AutoSizeMode = DataGridViewAutoSizeColumnMode.ColumnHeader
        UserPaid.DataPropertyName = "Paid" <<<THis is a column already in my Database ....so don't get confused
       UserPaid.Items.AddRange(New String() {"Yes", "NO"})
       UserPaid.Sorted = True
       UserPaid.SortMode = DataGridViewColumnSortMode.NotSortable
        UserPaid.HeaderText = "Compensated"
        User.Name = "Paid"
        User.DefaultCellStyle.BackColor = Color.Beige

        datagridview.Columns.Add(UserPaid) ..this pretty much adds what i define as a combobox to the grid..

Well enjoy..and for some who ask why post the code..well believe me I know many of us who connect our application to a database would like to have a combobox pulled in to fill in certain data to our database...plus I know how hard it is to be a noob and looking for answers :).

Take care guys and enjoy..also if there is any way to make this better or faster etc..just post up guys I will catch up.:)

Reply With Quote

Thread Tools Search this Thread
Search this Thread:

Advanced Search
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is Off
HTML code is Off
Trackbacks are Off
Pingbacks are On
Refbacks are Off

Similar Threads
Thread Thread Starter Forum Replies Last Post
Programmatically Add/Customize SSIS built in Loggi vinod.rajput SQL Server 2005 0 September 22nd, 2008 04:57 AM
Add Push button or Check Box in outlook add-ins capdevs VS.NET 2002/2003 0 January 7th, 2006 08:51 AM
Creating report programmatically liliarum BOOK: Professional SQL Server Reporting Services ISBN: 0-7645-6878-7 1 July 6th, 2004 09:34 AM

All times are GMT -4. The time now is 05:33 AM.

Powered by vBulletin®
Copyright ©2000 - 2020, Jelsoft Enterprises Ltd.
© 2013 John Wiley & Sons, Inc.