从另一个模态窗体修改打开的窗体上的控件?

时间:2013-07-09 20:46:20

标签: vb.net telerik

如何从其他表单引用控件,例如我从另一个具有DataGrid的表单中打开一个模态表单,如何从模态表单向RadGridView添加行。

formA打开 - >按钮打开formB模态 - > formB代码将radgridview行添加到formA - > close formB - > formA添加了行:)

尝试从formB:

formA.radgridview1.rows.add("data")

无济于事(

1 个答案:

答案 0 :(得分:0)

在Form1内部和Form2内部将用作RadGridView数据源的DataTable声明为Data,而不是RadGridView。

Form1内部

Public DataTable1 As New DataTable

Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
    DataTable1.Columns.Add("data")
    DataTable1.Rows.Add("Test row from Form A")
    RadGridView1.DataSource = DataTable1
End Sub

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Dim Form2 As New Form2
    Form2.ShowDialog()
    Form2.Dispose()
End Sub

在Form2中

Private Sub Button1_Click(sender As System.Object, e As System.EventArgs) Handles Button1.Click
    Form1.DataTable1.Rows.Add("Test row from Form B")
End Sub