weixin_58317284 2021-07-14 22:33 采纳率: 0%
浏览 17

通过button给给DateGridView中填加textbooks文本内容填加不了

如下
Public Class Form1

Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
    Dim newRow As New DataGridViewRow()
    Dim newRowCell As New DataGridViewTextBoxCell
    newRow.Cells.Add(newRowCell)
    newRowCell = New DataGridViewTextBoxCell
    newRowCell.Value = Me.TextBox1.Text
    newRow.Cells.Add(newRowCell)
    DataGridView1.Rows.Add(newRowCell)

End Sub

End Class
运行图如下

  • 写回答

1条回答 默认 最新

  • 泡沫o0 2023年度博客之星上海赛道TOP 1 2023-06-17 20:54
    关注

    根据你的代码,你似乎是在尝试创建一个新的行(newRow),然后为这个行添加一个新的单元格(newRowCell)。然后你尝试将这个单元格的值设置为TextBox1的文本。但是,在你将新的行添加到DataGridView时,你却添加了新的单元格(newRowCell)而不是新的行(newRow)。这可能是问题所在。

    你应该改变你的代码,将新的行添加到DataGridView,而不是新的单元格。以下是修复后的代码:

    Public Class Form1
        Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
            Dim newRow As New DataGridViewRow()
            Dim newRowCell As New DataGridViewTextBoxCell
            newRowCell.Value = Me.TextBox1.Text
            newRow.Cells.Add(newRowCell)
            DataGridView1.Rows.Add(newRow)
        End Sub
    End Class
    

    这段代码会在你点击按钮时,为DataGridView1添加一行,这一行中的单元格包含TextBox1的文本。

    评论

报告相同问题?

问题事件

  • 创建了问题 7月14日

悬赏问题

  • ¥15 想问一下stata17中这段代码哪里有问题呀
  • ¥15 flink cdc无法实时同步mysql数据
  • ¥100 有人会搭建GPT-J-6B框架吗?有偿
  • ¥15 求差集那个函数有问题,有无佬可以解决
  • ¥15 【提问】基于Invest的水源涵养
  • ¥20 微信网友居然可以通过vx号找到我绑的手机号
  • ¥15 寻一个支付宝扫码远程授权登录的软件助手app
  • ¥15 解riccati方程组
  • ¥15 使用rabbitMQ 消息队列作为url源进行多线程爬取时,总有几个url没有处理的问题。
  • ¥15 Ubuntu在安装序列比对软件STAR时出现报错如何解决