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