programmatically add DataGridViewComboBoxColumn

R

Rain County

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
 
M

mark carew

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
 
M

mark carew

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
 
R

Rain County

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
 

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