using the DataGridViewComboBoxColumn object

E

Ed Cohen

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 from the database (this also
has worked). But, now I want to be able to have the user select one of the
items in that combo box and fire off an event to select more data from the
database based on what the user selected in the combo box.

Well, this DataGrid version of the combo box is very different from the
regular version. The big this is that I cannot figure out what event is fired
when the user selects a combo box item and how one gets to the selected value
in that combo box.. Normally one would go to the ComboBox.SelectedValue (or
is it SelectedIndex?) and there you go. There is not such property, and I
have not figured out which DataGridView event to use to make this happen. Can
anyone help? Thank you.

Ed Cohen
 
A

Ashutosh Bhawasinka

you need to get the column which is set to be a combo box like this

DataGridViewComboBoxColumn col = dataGridView1.Columns[1] as
DataGridViewComboBoxColumn;
if(null != col)
{
//do your processing here
}

Secondly, in cases like this, you have these values set

col.DataSource = laneTypeTable; //name of the table
col.ValueMember = "LaneID"; // this field is used for value internally
col.DisplayMember = "Name"; //this is used for display only

For the event part, you can register for ColumnChanging event of the
table which you are displaying in the grid.

Thanks & Regards,
Ashutosh Bhawasinka
 

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