471,577 Members | 1,562 Online
Bytes | Software Development & Data Engineering Community
Post +

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 471,577 software developers and data experts.

programmatically add DataGridViewComboBoxColumn

I am programmatically building and populating a table and then making it the
data source for a dataGridView. I want to add a column to the dataGridView
which will be a DataGridViewComboBoxColumn. I wish to populate, by default,
all of the ComboBoxes with the same list of three choices.

How do I add the DataGridViewComboBoxColumn, and do I first populate one as
a template for the others?

I will appreciate any help.

Thanks,
Phil
Feb 7 '06 #1
3 22016
On Mon, 6 Feb 2006 19:40:18 -0800, Rain County wrote:
I am programmatically building and populating a table and then making it the
data source for a dataGridView. I want to add a column to the dataGridView
which will be a DataGridViewComboBoxColumn. I wish to populate, by default,
all of the ComboBoxes with the same list of three choices.

How do I add the DataGridViewComboBoxColumn, and do I first populate one as
a template for the others?

I will appreciate any help.

Thanks,
Phil


Hi Phil,

As far as I can figure, you add or insert the new
DataGridViewComboBoxColumn to the Columns collection of the DataGridView.

e.g.
dataGridView1.Columns.Insert(0,new DataGridViewComboBoxColumn());
or
dataGridView1.Columns.Add(new DataGridViewComboBoxColumn());

This comboBoxColumn has to have an array added to its Items collection,
that defines its possible values. Thus, the above is simplified and the
ComboBoxColumn would be created and passed into the Insert or Add method
above.

These values are set at DataGridViewRow load time to show the values in the
DataGridView combo cells, thus you need a link to datasource that can
derive these invididual row values.

There is a good example in the doco under the (.NET SDK Framework)
DataGridViewComboBoxColumn that does both an add and an insert.

DataGridViews consist of bands (row and column) and cells, so in this case
you are creating and configuring a column as a unique entity.

HTH
Mark
Feb 7 '06 #2

Hi Phil

Further Info.

The example that I mentioned has a requirement for a northhwind sql
database. You will have to change the "Data Source" entry in
connectionString from localhost to an sql server name to get it to run.

I have a local sql2000 advanced server whose name is 'MAGIC-60768C???'.
Once I replaced the localhost with this quoted string and recompiled the
example runs up without any problems.

It has
. two comboboxcolumns
. a push button column
. an image column
. a link column
. a checkbox column

It is a master details app showing orders per employee and has
illustrations of most different types of DataGridViewCell including decimal
numeric.

IMHO Its well worth a look.

HTH
Mark
Feb 7 '06 #3
Thank you Mark, your replies are a great help. As they say, the devil is
in the details, but the general framework that you have presented gets me
more than halfway there. I will hit the reference you provided as well.

I appreciate you and the others here that take the time to help those of us
in need.

Phil

"mark carew" <ma*******@magicwanddept.com.au> wrote in message
news:1x*****************************@40tude.net...
On Mon, 6 Feb 2006 19:40:18 -0800, Rain County wrote:
I am programmatically building and populating a table and then making it
the
data source for a dataGridView. I want to add a column to the
dataGridView
which will be a DataGridViewComboBoxColumn. I wish to populate, by
default,
all of the ComboBoxes with the same list of three choices.

How do I add the DataGridViewComboBoxColumn, and do I first populate one
as
a template for the others?

I will appreciate any help.

Thanks,
Phil


Hi Phil,

As far as I can figure, you add or insert the new
DataGridViewComboBoxColumn to the Columns collection of the DataGridView.

e.g.
dataGridView1.Columns.Insert(0,new DataGridViewComboBoxColumn());
or
dataGridView1.Columns.Add(new DataGridViewComboBoxColumn());

This comboBoxColumn has to have an array added to its Items collection,
that defines its possible values. Thus, the above is simplified and the
ComboBoxColumn would be created and passed into the Insert or Add method
above.

These values are set at DataGridViewRow load time to show the values in
the
DataGridView combo cells, thus you need a link to datasource that can
derive these invididual row values.

There is a good example in the doco under the (.NET SDK Framework)
DataGridViewComboBoxColumn that does both an add and an insert.

DataGridViews consist of bands (row and column) and cells, so in this case
you are creating and configuring a column as a unique entity.

HTH
Mark

Feb 8 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by philip | last post: by
4 posts views Thread by John | last post: by
reply views Thread by Chris Botha | last post: by
1 post views Thread by =?Utf-8?B?RWQgQ29oZW4=?= | last post: by
reply views Thread by XIAOLAOHU | last post: by
reply views Thread by lumer26 | last post: by
reply views Thread by Vinnie | last post: by
1 post views Thread by lumer26 | last post: by
reply views Thread by lumer26 | last post: by

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.