如何在已经设计的Windows表单上访问DataGridView属性

发布于 2025-01-23 22:08:37 字数 377 浏览 1 评论 0原文

我已经在上面设计了一个带有datagridview的Windows表单( form1 ),我还有一个带有一个带有一个按钮的功能区,当我单击它时,它可以在其中运行像Bellow这样的代码:

Private Sub Button2_Click(sender As Object, e As RibbonControlEventArgs) Handles 
Button2.Click
    Dim f As Form1
    f = New Form1
    f.Show()
'(Room for my question)
end sub

我希望能够访问我的DataGridView用户控件以编程添加列和行。

我应该怎么做?

I had already designed a windows form (Form1) with a DataGridView on it, I also have a ribbon with a button on it in which I want when I click on it, it run a code like bellow:

Private Sub Button2_Click(sender As Object, e As RibbonControlEventArgs) Handles 
Button2.Click
    Dim f As Form1
    f = New Form1
    f.Show()
'(Room for my question)
end sub

I want to be able to access my datagridview user control to add columns and rows programmatically.

How should I do that?

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

递刀给你 2025-01-30 22:08:37

您可以在表单上创建一个公共子,您将在该表格上放置要进行的更改,然后在form2的button2_click事件上调用它。

例子:
表格1:

Public Sub AddToDGV()
    With DataGridView1
        .Rows.Add(Form2.TextBox1.Text, Form2.TextBox2.Text, Form2.TextBox3.Text)
    End With
End Sub

form2:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Call Form1.AddToDGV()
End Sub

You can create a Public Sub on form one which where you will put the changes that you want make on the the Datagridview then call it on the Button2_Click event of your Form2.

Example:
Form 1:

Public Sub AddToDGV()
    With DataGridView1
        .Rows.Add(Form2.TextBox1.Text, Form2.TextBox2.Text, Form2.TextBox3.Text)
    End With
End Sub

Form2:

 Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
    Call Form1.AddToDGV()
End Sub
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文