DataGridView and Combobox columns

G

Guest

I am trying to populate a DataGridView Combobox column with a different data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the following
properties dynamically in code?

DataPropertyName
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.
 
G

Guest

Hi,
try this code :

DataGridViewComboBoxCell dgvComBox = GetComboBox();

private void DataGridViewComboBoxCell GetComboBox()
{
DataGridViewComboBoxCell dgvComboBoxCell = new DataGridViewComboBoxCell
();
dgvComboBoxCell .ToolTipText = "Some Text ";
dgvComboBoxCell.DataSource = "Your Datasource";
dgvComboBoxCell.DisplayMember = "DisplayColumnName";
dgvComboBoxCell ="ValueColumnName"
return dgvComboBoxCell ;
}

Thereafter you can assign this to datagridview cell in following manner:
dgvDataGridName.Rows[somecount].Cells[somecount] = dgvComBox ;

please let me know if this has worked.
 
G

Guest

Page 62 of this coument has the answer:
http://www.windowsforms.net/Samples/Go To Market/DataGridView/DataGridView FAQ.doc


Manish Bafna said:
Hi,
try this code :

DataGridViewComboBoxCell dgvComBox = GetComboBox();

private void DataGridViewComboBoxCell GetComboBox()
{
DataGridViewComboBoxCell dgvComboBoxCell = new DataGridViewComboBoxCell
();
dgvComboBoxCell .ToolTipText = "Some Text ";
dgvComboBoxCell.DataSource = "Your Datasource";
dgvComboBoxCell.DisplayMember = "DisplayColumnName";
dgvComboBoxCell ="ValueColumnName"
return dgvComboBoxCell ;
}

Thereafter you can assign this to datagridview cell in following manner:
dgvDataGridName.Rows[somecount].Cells[somecount] = dgvComBox ;

please let me know if this has worked.

--
If my answer helped you,then please do press Yes below.
Thanks and Regards.
Manish Bafna.
MCP and MCTS.



Chris said:
I am trying to populate a DataGridView Combobox column with a different data
binding source (dataset) depending upon a selection made in a previous
column. I can handle the previous column but how do I assign the following
properties dynamically in code?

DataPropertyName
DataSource
DisplayMember

I do see how to set these at design time but that won't do because I need
different data in the combobox per each row depending upon the previous
selection made.
I hope I explained the problem well enough.
 

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