-3

I need to fill a combobox on a form with the column names from an existing data table. I don't want to manually enter the column names in case they change in the future. I also want to keep my code tidy, so I don't want a standard loop. How can I fill a combobox with the column names most efficiently?

1 Answer 1

2

Thanks to examples from here, here, and here, I was able to piece together the following LINQ query and set it directly to the data source on the combobox when the form loads.

Private Sub Form_Load(sender As Object, e As EventArgs) Handles Me.Load
    comboBox.DataSource = (From dc In dataTable.Columns
                             Select dc.ColumnName).ToArray()
End Sub
Sign up to request clarification or add additional context in comments.

Comments

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.