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

前端 未结 5 1336
萌比男神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:15

    If you are doing WinForm, the important part is setting the DataPropertyName property to match the DataTable Column name. You can do it in the designer or code as follows:

    Me.AccountDataGridView.Columns("Account").DataPropertyName = "Account"
    

    Of course, having set this:

    Me.AccountDataGridView.AutoGenerateColumns = False
    

提交回复
热议问题