How to get a DataGridView column to show as combo box.

B

bill.jenner

I have two related tables I wish to use in a grid. The second table has
to drive the list of items apart of a combo box apart of one of the
grids columns. Table 1 schema has columns ( . . . . "Department" . . .
) and needs to populate the entire grid. Table 2 schema had one column
("Department") and needs to populate a combo box attached to one column
of the grid. I attempted to configure this using the DataGridView
wizard but I wasn't able to bind the grid to one source while binding
the combo box column to the other. Any ideas appreciated.
 
C

Cor Ligthert [MVP]

Bill,

I understand from Attached that you mean a combobox outside the
datagridview.

The most simple form for that is using the datarelations. See our website,
there is more however here one very simple sample about that using two
datagrids.

http://www.vb-tips.com/default.aspx?ID=d667d78f-4b08-42ef-ba3b-8b8620d93761

I hope this helps,

Cor

ps. I have a sample with an outside attached combobox however because it is
in fact not logical never placed that on this website. Have as well a look
for a combobox inside your datagridview. This was something that was not in
a datagrid and therefore you see samples on our website how to do it with a
datagrid.

From a message from Pieter to this newsgroup, I have understood that the
inbuild combobox in the datagridview is the most simple format, I did not
use that yet.
 
C

Cor Ligthert [MVP]

Bill,

I see in a message from you to Kay that the sample I gave you is not what
you need, I did not do this with a datagridview, however if you want that,
than I can try, can be interesting.

Cor
 
B

bill.jenner

Cor & Ken,

Thanks for the input. I didn't take the time to read the msdn link
yet but will check it out later today. To clarify my statement above: I
actually am trying to build the Combo box inside the data grid.
Playing with Visual Studio 2005 is a little different and takes some
effort getting use to. At first I didn't like it but as I make
progress, I'm liking it more and more. Using the "Data Source window" I
was able to accomplish most of my task. Here is what I did: Open data
source window, using the add connection wizard (displayed at top of the
window), established and complete the steps for a connection to DB
tables of interest, now select one of the tables displayed in the Data
Source window and expand it to display all the fields, select one of
the fields and click on the down arrow attached to the right side of
it, select combo-box, drag the table onto the form. The grid now has
data source attached and combo-box inside of it. The next trick I still
have to due is attached the second table to the "items" property
associated with my combo box field.
 
B

bill.jenner

Cor & Ken,

Thanks for the input. I didn't take the time to read the msdn link
yet but will check it out later today. To clarify my statement above: I
actually am trying to build the Combo box inside the data grid.
Playing with Visual Studio 2005 is a little different and takes some
effort getting use to. At first I didn't like it but as I make
progress, I'm liking it more and more. Using the "Data Source window" I
was able to accomplish most of my task. Here is what I did: Open data
source window, using the add connection wizard (displayed at top of the
window), established and complete the steps for a connection to DB
tables of interest, now select one of the tables displayed in the Data
Source window and expand it to display all the fields, select one of
the fields and click on the down arrow attached to the right side of
it, select combo-box, drag the table onto the form. The grid now has
data source attached and combo-box inside of it. The next trick I still
have to due is attached the second table to the "items" property
associated with my combo box field.
 
C

Cor Ligthert [MVP]

Bill,

I tried it using completely the designer.

I opened the data -> datasource and selected in that wizard the NorthWind
database with the tables customers and customerorders.

Than I dragged a datagridview on my form

I set the properties datasource of that (opening that property until I had
by clicking the plus buttons the order table).

After that I opened the edit columns with the link at the bottom. I choise
the idcustomercolumn and said that it was a combobox. I set for that the
datasource to the customer table and set as well the displaymember to
customername and the valuemember to customerid

Than I started debug and it was running showing a nice datagridview with a
combobox with the names of the customers in it, that I could select to
change those.

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top