By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
459,282 Members | 1,549 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 459,282 IT Pros & Developers. It's quick & easy.

ComboBoxes in DataGridViews bound to DataSources

P: n/a
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to display
a ComboBox?

Thanks,
John

Nov 29 '06 #1
Share this Question
Share on Google+
5 Replies


P: n/a
Hi

Why don"t you use the extended properties of Datacolumn of the Datatable ?
<jj******@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to display
a ComboBox?

Thanks,
John

Nov 29 '06 #2

P: n/a
It needs to be automatic; it takes 45 seconds to load 5,000 rows
without binding, but only 6 seconds with binding. Somehow, I need to
have the DataSource create a ComboBox column automatically.

- John

Thierry wrote:
Hi

Why don"t you use the extended properties of Datacolumn of the Datatable ?
<jj******@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to display
a ComboBox?

Thanks,
John
Nov 29 '06 #3

P: n/a
In Brian Noyes' databinding book, he has one example where
he creates a DataGridView, and has different kinds of columns
in it. One of them is a dropdown combo box. He says this is
one of the most complicated to implement.

I recommend that you go to his website
www.softinsight.com/databindingbook
and download the code and look at the project in Chapter6
called ColumnTypes.

I'd post some of it here, but there's a lot of it,
tied to different events (like editing the grid).

If you want to run it, you will need to set up the database
he's using; those scripts are on the same webpage.

Then you should buy this book; it's invaluable.

Robin S.
---------------------------

<jj******@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
It needs to be automatic; it takes 45 seconds to load 5,000 rows
without binding, but only 6 seconds with binding. Somehow, I need to
have the DataSource create a ComboBox column automatically.

- John

Thierry wrote:
Hi

Why don"t you use the extended properties of Datacolumn of the Datatable ?
<jj******@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to display
a ComboBox?

Thanks,
John

Nov 30 '06 #4

P: n/a
Ah ha! Thanks, that had what I needed. In case anyone else is
wondering, here's what you do:
1. Create a DataGridView with the columns and column types (text,
combobox, checkbox, etc) that you want.
2. Set DataGridView.AutoGenerateColumns to false.
3. Create and fill a DataTable with your data.
4. The important (and non-obvious) part: each existing column in the
DataGridView must be individually connected to its corresponding column
in the DataTable:
DataGridView.Columns[0].DataPropertyName = "Column0";
DataGridView.Columns[1].DataPropertyName = "Column1";
...
5. Set DataGridView.DataSource to the DataTable from 3.

You would think that if AutoGenerateColumns is false, the grid would
automatically connect its columns to the columns of its DataSource, but
I guess it would be too hard to figure out if it's supposed to match
them by position or name or something else, so they left it up to the
programmer.

- John

RobinS wrote:
In Brian Noyes' databinding book, he has one example where
he creates a DataGridView, and has different kinds of columns
in it. One of them is a dropdown combo box. He says this is
one of the most complicated to implement.

I recommend that you go to his website
www.softinsight.com/databindingbook
and download the code and look at the project in Chapter6
called ColumnTypes.

I'd post some of it here, but there's a lot of it,
tied to different events (like editing the grid).

If you want to run it, you will need to set up the database
he's using; those scripts are on the same webpage.

Then you should buy this book; it's invaluable.

Robin S.
---------------------------

<jj******@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
It needs to be automatic; it takes 45 seconds to load 5,000 rows
without binding, but only 6 seconds with binding. Somehow, I need to
have the DataSource create a ComboBox column automatically.

- John

Thierry wrote:
Hi

Why don"t you use the extended properties of Datacolumn of the Datatable ?
<jj******@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to display
a ComboBox?
>
Thanks,
John
>
Dec 1 '06 #5

P: n/a
But don't you also have to connect the column of the combobox
to the list of values you want to see in it?

Robin S.
--------------------------
<jj******@gmail.comwrote in message
news:11*********************@79g2000cws.googlegrou ps.com...
Ah ha! Thanks, that had what I needed. In case anyone else is
wondering, here's what you do:
1. Create a DataGridView with the columns and column types (text,
combobox, checkbox, etc) that you want.
2. Set DataGridView.AutoGenerateColumns to false.
3. Create and fill a DataTable with your data.
4. The important (and non-obvious) part: each existing column in the
DataGridView must be individually connected to its corresponding column
in the DataTable:
DataGridView.Columns[0].DataPropertyName = "Column0";
DataGridView.Columns[1].DataPropertyName = "Column1";
...
5. Set DataGridView.DataSource to the DataTable from 3.

You would think that if AutoGenerateColumns is false, the grid would
automatically connect its columns to the columns of its DataSource, but
I guess it would be too hard to figure out if it's supposed to match
them by position or name or something else, so they left it up to the
programmer.

- John

RobinS wrote:
In Brian Noyes' databinding book, he has one example where
he creates a DataGridView, and has different kinds of columns
in it. One of them is a dropdown combo box. He says this is
one of the most complicated to implement.

I recommend that you go to his website
www.softinsight.com/databindingbook
and download the code and look at the project in Chapter6
called ColumnTypes.

I'd post some of it here, but there's a lot of it,
tied to different events (like editing the grid).

If you want to run it, you will need to set up the database
he's using; those scripts are on the same webpage.

Then you should buy this book; it's invaluable.

Robin S.
---------------------------

<jj******@gmail.comwrote in message
news:11**********************@l12g2000cwl.googlegr oups.com...
It needs to be automatic; it takes 45 seconds to load 5,000 rows
without binding, but only 6 seconds with binding. Somehow, I need to
have the DataSource create a ComboBox column automatically.

- John

Thierry wrote:
Hi

Why don"t you use the extended properties of Datacolumn of the Datatable
?
<jj******@gmail.coma écrit dans le message de news:
11**********************@j72g2000cwa.googlegroups. com...
Hi all,
I've got a DataGridView bound to a DataTable, and I need to make
some of the columns into ComboBoxColumns. I've tried some of the
solutions listed here, but I can't seem to make them work. They might
not be the solutions I'm looking for; I just want to have a few
arbitrary values for a combo box and make sure everything in that row
is one of those values. My boss won't let me just leave them as text
boxes. How do I tell the DataTable to tell the DataGridView to
display
a ComboBox?
>
Thanks,
John
>

Dec 1 '06 #6

This discussion thread is closed

Replies have been disabled for this discussion.