How to access combo box properties of DataGridView combo column

  • Thread starter Thread starter Steve Marshall
  • Start date Start date
S

Steve Marshall

Hi, I have an unbound DataGridView with just 1 column in it. The
column is a combobox type, and I need to be able to attach the
datasource to it programmatically. This is because it is a DataTable
that gets built dynamically at runtime. But I can't see how to get at
the underlying combobox that "belongs" to the column. Anyone know how
to do this? It has to be in there somewhere! There doesn't even seem
to be a DataGridViewComboBoxColumn object (or similar), so obviously I
am looking in the wrong direction. Somebody please adjust my
headspace!
 
You have a DataGridView with just 1 column in it, and it is "a combobox
type," but you say that there doesn't seem to be a
DataGridViewComboBoxColumn "object" - - what exactly do you think the
"combobox type" column in your DataGridView is? Well, apparently you do not
know, but it's a DataGridViewComboBoxColumn. You even got the name right! In
fact, there are several classes associated with this one:

DataGridViewComboBoxColumn
DataGridViewComboBoxCell
DataGridViewComboBoxEditingControl
DataGridViewComboBoxCell.ObjectCollection
DataGridViewComboBoxDisplayStyle

So, I'm scratching my head trying to figure out where the disconnect is,
here. My guess is that you are aware that the DataGridView has a Columns
Collection, which is a Collection of DataGridViewColumn instances, a Rows
Collection, which is a Collection of DataGridViewRow instances, and that
each row has a Collection of DataGridViewCell instances. Now, you'll notice
that in my list there is a DataGridViewComboBoxCell class.
DataGridViewComboBoxColumn inherits DataGridViewColumn, and
DataGridViewComboBoxCell inherits DataGridViewCell. This is so that you can
add a DataGridViewComboBoxColumn to a DataGridView, or any other type of
DataGridViewColumn-derived class. In other words, all you have to do is cast
it as a DataGridViewComboBoxCell to get at its unique properties.

--
HTH,

Kevin Spencer
Microsoft MVP

Printing Components, Email Components,
FTP Client Classes, Enhanced Data Controls, much more.
DSI PrintManager, Miradyne Component Libraries:
http://www.miradyne.net
 
Yeah, a Momentary Lapse of Reason, to quote Pink Floyd. Sorry to
waste anyone's time. I was originally trying to type
DataGridComboBoxColumn (without the 'View" in it), and of course there
ain't no such! When I posted the message here, my brain must have
clicked into gear. Yes, I have found all the objects and all is well
in combobox-column-land. Thanks.
 
Back
Top