How to bind dataGridView predefined columns with columns from sql statement (without adding new columns)?

前端 未结 5 1343
萌比男神i
萌比男神i 2021-02-13 22:30

Is there a elegant way, to bind predefined dataGridView columns with results from a SQL statement?

Example:

dataGridView1.Columns.Add(\"EID\", \"ID\");
d         


        
5条回答
  •  夕颜
    夕颜 (楼主)
    2021-02-13 23:19

    Aside from setting AutoGenerateColumns to false, you also need to set DataPropertyName for each column in the DataGridView to the corresponding field in the data source. You can set this in the designer or in code before setting the DataSource property.

提交回复
热议问题