C#, WinForms, DataGridViewComboBoxColumn

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

I'm using a datagridview that's populate from a products table.

In the grid, I need to have combo box column, that's populated from a
different table, but needs to be selected from the rows in the products table.

Anyone with sample or links that accomplishes this? I can't seem to find
anything in Google about binding the combo box to the grid table.
 
Okay, it's a little confusing, but not as hard as it might seem. The
DataGridView itself has a DataSource property that determines what columns
are in it. The DataGridViewComboBox column also has a DataSource property,
but that isn't the same as the DataSource of the DataGridView. It is the
DataSource that is used to populate the ComboBox in each cell. The
DataMember and ValueMember properties are the column names of the columns in
the ComboBox's DataSource that define what is displayed in the ComboBox, and
the underlying value for that item. It is the DataPropertyName property of
the DataGridViewComboBoxColumn that determines the column name in the
DataGridView's DataSource that the DataGridViewComboBoxColumn is associated
with. The ValueMember determines the value that will be set for that column
in the DataGridView's DataSource.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Thank you!


Kevin Spencer said:
Okay, it's a little confusing, but not as hard as it might seem. The
DataGridView itself has a DataSource property that determines what columns
are in it. The DataGridViewComboBox column also has a DataSource property,
but that isn't the same as the DataSource of the DataGridView. It is the
DataSource that is used to populate the ComboBox in each cell. The
DataMember and ValueMember properties are the column names of the columns in
the ComboBox's DataSource that define what is displayed in the ComboBox, and
the underlying value for that item. It is the DataPropertyName property of
the DataGridViewComboBoxColumn that determines the column name in the
DataGridView's DataSource that the DataGridViewComboBoxColumn is associated
with. The ValueMember determines the value that will be set for that column
in the DataGridView's DataSource.

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
No problem. While the DataGridView is a masterwork of architecture, it is
also a monster in terms of sheer size and complexity. It took me a good
while to figure out some of these things for myself!

--
HTH,

Kevin Spencer
Microsoft MVP
Professional Numbskull

Hard work is a medication for which
there is no placebo.
 
Back
Top