Datagridview列名称不变

时间:2014-02-14 15:12:54

标签: mysql vb.net datagridview multiple-columns

这是我的代码,我认为它没有任何问题,但我的列名仍然与mysql中的名称相同。

Private Sub DGVShareholder_CellContentClick(sender As System.Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles DGVShareholder.CellContentClick

    Me.DGVShareholder.Columns(1).HeaderText = "Company Name"
    Me.DGVShareholder.Columns(2).HeaderText = "Position"
    Me.DGVShareholder.Columns(3).HeaderText = "NI"
    Me.DGVShareholder.Columns(4).HeaderText = "Forename"
    Me.DGVShareholder.Columns(5).HeaderText = "Surname"
    Me.DGVShareholder.Columns(6).HeaderText = "D.O.B"
    Me.DGVShareholder.Columns(7).HeaderText = "Address Line 1"
    Me.DGVShareholder.Columns(8).HeaderText = "City"
    Me.DGVShareholder.Columns(9).HeaderText = "Postcode"
    Me.DGVShareholder.Columns(10).HeaderText = "Email"
    Me.DGVShareholder.Columns(11).HeaderText = "Phone Number"
End Sub

1 个答案:

答案 0 :(得分:1)

无法理解为什么这不起作用。在我将DataGridView设置为从DataSource查询转储的表后,我会定期更改SQL的标题

查看更改标题后是否再次覆盖DataGridView或尝试应用DataSourceChangedDataBindingComplete事件等内容,以便在更改数据后修改标题< / p>

Private Sub DGVShareholder_DataSourceChanged(sender As Object, e As System.EventArgs) Handles DGVShareholder.DataSourceChanged

    Dim i = 0
    For Each column As DataGridViewColumn In Me.DGVShareholder.Columns
        column.HeaderText = i
        i += 10
    Next

End Sub