Note that there are some explanatory texts on larger screens.

plurals
  1. POCascade combobox in datagridview not working properly
    text
    copied!<p>I got stuck while implementing cascade <code>ComboBox</code> in Windows Form. I have a <code>DataSet</code> with some <code>DataTable</code>. Now, I have a <code>DataGridView</code> control which will have two <code>ComboBox</code> : </p> <ul> <li>One <code>ComboBox</code> will display all the <code>DataTable</code> names </li> <li>Another will be filled with the column names of the selected <code>DataTable</code></li> </ul> <p>Problem is that cascading is not working properly. Full Code is below :</p> <pre><code>DataSet ds = new DataSet(); public Form1() { InitializeComponent(); } private void Form1_Load(object sender, EventArgs e) { ds.Tables.Add(GetTable1()); ds.Tables.Add(GetTable2()); IList&lt;string&gt; lstTables = ds.Tables.OfType&lt;DataTable&gt;().Select(dt =&gt; dt.TableName).ToList(); dgvColumn1.DataSource = lstTables; dgvColumn1.ValueType = typeof(string); } private void dataGridView1_CellValueChanged(object sender, DataGridViewCellEventArgs e) { if ((dataGridView1.CurrentCell != null) &amp;&amp; (dataGridView1.CurrentCell.ColumnIndex == 0)) { DataGridViewComboBoxColumn cboColumn = (DataGridViewComboBoxColumn)dataGridView1.Columns[1]; if (ds.Tables[dataGridView1.CurrentCell.FormattedValue.ToString()].Columns.Count &gt;0) { IList&lt;string&gt; lstColumn = ds.Tables[dataGridView1.CurrentCell.FormattedValue.ToString()].Columns.Cast&lt;DataColumn&gt;().Select(x =&gt; x.ColumnName).ToList(); cboColumn.DataSource = lstColumn; cboColumn.ValueType = typeof(string); } else { cboColumn.DataSource = null; } } } private void dataGridView1_DataError(object sender, DataGridViewDataErrorEventArgs e) { } DataTable GetTable1() { DataTable dt1 = new DataTable("table1"); dt1.Columns.Add("t1Col1"); dt1.Columns.Add("t1Col2"); dt1.Columns.Add("t1Col3"); dt1.Columns.Add("t1Col4"); return dt1; } DataTable GetTable2() { DataTable dt2 = new DataTable("table2"); dt2.Columns.Add("t2Col1"); dt2.Columns.Add("t2Col2"); dt2.Columns.Add("t2Col3"); dt2.Columns.Add("t2Col4"); return dt2; } </code></pre>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload