Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    primarykey
    data
    text
    <p><img src="https://i.stack.imgur.com/5SMzI.png" alt="enter image description here">I tried this:</p> <pre><code>private void Form1_Load_1(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(); dataGridView1.DataSource = lstTables; comboBox1.DataSource = lstTables; //Setting the tables datasource for the comboBox. } </code></pre> <p>and then the selection change of the table comboBox event:</p> <p>private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { </p> <pre><code> var obj = sender as ComboBox; string s = obj.SelectedItem.ToString(); var y= (from x in ds.Tables.OfType&lt;DataTable&gt;() where x.TableName == s select x).ToList(); if (ds.Tables.Count &gt; 0) { IList&lt;string&gt; lstCol = new List&lt;string&gt;(); for (int i = 0; i &lt; y[0].Columns.Count; i++) { // Filling the list of columns according to the selected table lstCol.Add(y[0].Columns[i].ToString()); } // Setting dataSource for the column ComboBox comboBox2.DataSource = lstCol; //comboBox2.ValueType = typeof(string); } else { comboBox2.DataSource = null; } } </code></pre> <p>Designer.cs</p> <pre><code>private void InitializeComponent() { this.dataGridView1 = new System.Windows.Forms.DataGridView(); this.comboBox1 = new System.Windows.Forms.ComboBox(); this.comboBox2 = new System.Windows.Forms.ComboBox(); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).BeginInit(); this.SuspendLayout(); // // dataGridView1 // this.dataGridView1.AllowUserToAddRows = false; this.dataGridView1.AllowUserToDeleteRows = false; this.dataGridView1.ColumnHeadersHeightSizeMode = System.Windows.Forms.DataGridViewColumnHeadersHeightSizeMode.AutoSize; this.dataGridView1.Location = new System.Drawing.Point(26, 72); this.dataGridView1.Name = "dataGridView1"; this.dataGridView1.Size = new System.Drawing.Size(246, 150); this.dataGridView1.TabIndex = 0; this.dataGridView1.CellValueChanged += new System.Windows.Forms.DataGridViewCellEventHandler(this.dataGridView1_CellValueChanged_1); // // comboBox1 // this.comboBox1.FormattingEnabled = true; this.comboBox1.Location = new System.Drawing.Point(28, 74); this.comboBox1.Name = "comboBox1"; this.comboBox1.Size = new System.Drawing.Size(121, 21); this.comboBox1.TabIndex = 1; this.comboBox1.SelectedIndexChanged += new System.EventHandler(this.comboBox1_SelectedIndexChanged); // // comboBox2 // this.comboBox2.FormattingEnabled = true; this.comboBox2.Location = new System.Drawing.Point(148, 74); this.comboBox2.Name = "comboBox2"; this.comboBox2.Size = new System.Drawing.Size(121, 21); this.comboBox2.TabIndex = 2; // // Form1 // this.AutoScaleDimensions = new System.Drawing.SizeF(6F, 13F); this.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font; this.ClientSize = new System.Drawing.Size(284, 261); this.Controls.Add(this.comboBox2); this.Controls.Add(this.comboBox1); this.Controls.Add(this.dataGridView1); this.Name = "Form1"; this.Text = "Form1"; this.Load += new System.EventHandler(this.Form1_Load_1); ((System.ComponentModel.ISupportInitialize)(this.dataGridView1)).EndInit(); this.ResumeLayout(false); } </code></pre>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

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