【问题标题】:Datagridview column name not changingDatagridview 列名不变
【发布时间】:2014-02-14 15:12:53
【问题描述】:

这是我的代码,我认为它没有任何问题,但我的列名仍然与 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

【问题讨论】:

  • 你为什么要在这个活动中改变它们?是否发生此事件?
  • 您是否有任何类型为 DataGridViewButtonCell 或 DataGridViewLinkCell 的单元格? CellContentClick 事件仅在单击这些单元格时触发。我同意 DonA,除非需要更改某些内容,否则指定标题文本的地方很奇怪?
  • 我知道这是错误的地方,但我正在试验,因为我不知道放在哪里?
  • 为什么不使用设计师。在那里您可以创建具有不同 Header 和 DataPropertyName(来自数据库的列名)的预定义列?

标签: mysql vb.net datagridview multiple-columns


【解决方案1】:

不明白为什么这不起作用。在将DataSource 设置为从SQL 查询中转储的表后,我会定期更改DataGridViews 的标题

查看更改标题后DataGridView 是否再次被覆盖,或尝试应用DataSourceChangedDataBindingComplete 之类的事件,以便在更改数据后修改标题

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

【讨论】:

    猜你喜欢
    • 1970-01-01
    • 2010-09-12
    • 1970-01-01
    • 2023-03-07
    • 1970-01-01
    • 1970-01-01
    • 2015-04-16
    • 1970-01-01
    • 1970-01-01
    相关资源
    最近更新 更多