Changing a datagridview's combobox items based on another combobox

Please support our C# advertiser: Intel Parallel Studio Home
Reply

Join Date: Aug 2006
Posts: 17
Reputation: mstester is an unknown quantity at this point 
Solved Threads: 0
mstester mstester is offline Offline
Newbie Poster

Changing a datagridview's combobox items based on another combobox

 
0
  #1
Jun 4th, 2007
Hey guys,

I have a datagridview called DataGridView1 which has four column each are combobox's, I need to be able to change the items in one of the comboboxes based on the previous one. For example

I have a column named FieldName which has the following values:

1.Product
2. ID

if the user selects products i want to be able to change a combobox called Value to "HomeProject","Work Stuff"

Would anyone have any ideas on how to do this.

If searched around and could not find anything...please help

Thanks in advance
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: dox is an unknown quantity at this point 
Solved Threads: 0
dox dox is offline Offline
Newbie Poster

Re: Changing a datagridview's combobox items based on another combobox

 
0
  #2
Nov 6th, 2007
Assuming you've defined each column of type DataGridViewComboBoxColumn, you'll want to add a handlers for the events: EditingControlShowing and CellBeginEdit. We use CellBeginEdit to identify the active cell and EditingControlShowing to obtain the edit control. The args DataGridViewCellCancelEventArgs and DataGridViewEditingControlShowingEventArgs provide us with the data access we need to set the dropdown list.

e.g

private void dgv_CellBeginEdit(object sender, DataGridViewCellCancelEventArgs e)
{
m_iActiveCellCol = e.ColumnIndex;
}

private void dgv_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e)
{
ComboBox cbx;
if(m_iActiveCellCol ==2)
{
cbx = (ComboBox)e.Control;
cbx.DataSource = m_oCol2DataSource;
cbx.DisplayMember = oCol2DataSource.DisplayMember;
}
}
Reply With Quote Quick reply to this message  
Join Date: Nov 2007
Posts: 2
Reputation: dox is an unknown quantity at this point 
Solved Threads: 0
dox dox is offline Offline
Newbie Poster

Re: Changing a datagridview's combobox items based on another combobox

 
0
  #3
Nov 6th, 2007
A much easier way in fact is to simple cast the particular column that you want to modify as the code below demonstrates:

DataGridViewComboBoxColumn col = (DataGridViewComboBoxColumn)dgv.Columns["Value"];
col.Items.Add("HomeProject");
col.Items.Add("Work Stuff");
Reply With Quote Quick reply to this message  
Reply

This thread is more than three months old.
Perhaps start a new thread instead?
Message:


Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC