C# Bind DataTable to Existing DataGridView Column Definitions

前端 未结 2 435
无人共我
无人共我 2021-02-04 05:35

I\'ve been struggling with a NullReferenceException and hope someone here will be able to point me in the right direction. I\'m trying to create and populate a DataTable and the

相关标签:
2条回答
  • 2021-02-04 06:20

    If the error occurs inside UpdateResults then it sounds like dataGridView is null.

    private void UpdateResults(DataTable entries)
    {
        dataGridView.DataSource = entries; // when is dataGridView set?
    }
    
    0 讨论(0)
  • 2021-02-04 06:26

    You need to ensure each column's DataPropertyName property is set to the corresponding name of the DataColumn's ColumnName.

    You may also need to set the DataGridView's AutoGenerateColumns property to false.

    I found the solution here.

    0 讨论(0)
提交回复
热议问题