| | |
Changing a datagridview's combobox items based on another combobox
Please support our C# advertiser: Intel Parallel Studio Home
![]() |
•
•
Join Date: Aug 2006
Posts: 17
Reputation:
Solved Threads: 0
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
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
•
•
Join Date: Nov 2007
Posts: 2
Reputation:
Solved Threads: 0
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;
}
}
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;
}
}
![]() |
Similar Threads
- Combobox.items and database (Pascal and Delphi)
- VB.NET ComboBox & Statusbar HELP! (VB.NET)
- How to best rank items based on vote data (PHP)
- combobox question (VB.NET)
- Issue related to combobox.... (VB.NET)
- Creating a Coordiantion (Grid Based) System for a text-based game. (C)
- Can anybody please help me with this code? (ASP.NET)
- HELP with VB project (Visual Basic 4 / 5 / 6)
Other Threads in the C# Forum
- Previous Thread: help in Coding required of ASP.net
- Next Thread: form level variable
| Thread Tools | Search this Thread |
.net access ado.net algorithm alignment array barchart bitmap box broadcast buttons c# chat check checkbox client color combobox control conversion csharp custom customactiondata database datagrid datagridview dataset datetime degrees development draganddrop drawing encryption enum event excel file files form format forms function gdi+ hospitalmanagementsystems httpwebrequest image index input install java label list listbox listener mandelbrot math mouseclick mysql networking operator path photoshop picturebox pixelinversion post prime programming radians regex remote remoting richtextbox save saving serialization server sleep socket sql statistics stream string table tcp text textbox thread time timer treeview update usercontrol validation view visualstudio webbrowser windows winforms wpf xml





