473,385 Members | 1,888 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,385 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 22121
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
by: Shawn | last post by:
I am trying to use a DataGridView to display one column of textboxes with a single value from a query and then next to it have a combobox that displays results from another query. What happens is...
3
by: philip | last post by:
I have a datagridview with some columns. One of them has been declared as a DatagridviewComboboxColumn The datasource of this column is a table of an Access Database. There is 13000 lines in...
4
by: John | last post by:
Hi, I've been trying to populate a DataGridViewComboBoxColumn with objects. The object is defined as : private struct manufactItem { public string name; public Guid? man_id;
0
by: Chris Botha | last post by:
Using VS2005, on the form is a DataGridView, a typed DataSet containing the data and a BindingSource between the grid and the dataset. One of the columns is a DataGridViewComboBoxColumn, doing what...
0
by: Simon Tamman | last post by:
How do other people get around having to define the ValueMember in a DataGridViewComboBoxColumn when binding to a list of business objects? I'm currently doing the following, and it feels wrong...
0
by: Ken | last post by:
Hi I have a little application that does datavalidation. It supports dynamically loaded plugins (you drop a dll with a class implementing IValidator<Tin the same dir as the main application)....
1
by: sklett | last post by:
I have a DataGridView bound to a custom business object. The business object has 2 attributes that are FKs to a lookup table (think HairColorID, EyeColorID, etc) For these 2 columns I have...
0
by: ajey | last post by:
hi all! Im doing a windows application (C#), i have a datagridview bound from a Sql database in which i want one column to be ComboBox.I use DataGridViewComboBoxColumn and bind that column value.......
1
by: =?Utf-8?B?RWQgQ29oZW4=?= | last post by:
I have tried to use the DataGridComboBoxColumn object with limited success. What I want to do is to create one new unbound column to be a combo box (so far, this has worked), populate it with items...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.