Data Grid View Column Headers
-
Hello, I have a data grid view, and what I am trying to do is, grab all the column headers and put them into a combo box or list box. what I have so far is: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.ToString()); } I get an error with this, it is: "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Data.DataColumn'" Any help would be apreciated. Thanks J
-
Hello, I have a data grid view, and what I am trying to do is, grab all the column headers and put them into a combo box or list box. what I have so far is: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.ToString()); } I get an error with this, it is: "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Data.DataColumn'" Any help would be apreciated. Thanks J
you can try: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.HeaderText); }
-
Hello, I have a data grid view, and what I am trying to do is, grab all the column headers and put them into a combo box or list box. what I have so far is: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.ToString()); } I get an error with this, it is: "Unable to cast object of type 'System.Windows.Forms.DataGridViewTextBoxColumn' to type 'System.Data.DataColumn'" Any help would be apreciated. Thanks J
-
you can try: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.HeaderText); }
-
-
you can try: foreach (DataColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.HeaderText); }
-
Thank you for your help, I added a identifyer, and it worked great! Thanks. Here is the end result. foreach (DataGridViewColumn column in this.dataGridView1.Columns) { this.listBox1.Items.Add(column.HeaderText); }