Advertisement
MbahAgis

Passing Data Between Form

Aug 4th, 2020 (edited)
214
0
Never
Not a member of Pastebin yet? Sign Up, it unlocks many cool features!
VB.NET 1.17 KB | None | 0 0
  1. Public Class Form1
  2.     Private Sub BtnShow_Click(sender As Object, e As EventArgs) Handles BtnShow.Click
  3.         'show non duplicate form2
  4.         Dim frm As Form = My.Application.OpenForms.Item("Form2")
  5.         If frm IsNot Nothing Then
  6.             frm.Close()
  7.         End If
  8.  
  9.         Dim myChild As New Form2()
  10.         With myChild
  11.             .Owner = Me
  12.             .Show()
  13.         End With
  14.     End Sub
  15.  
  16.     Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  17.         Dim DT As New DataTable
  18.         DT.Columns.Add("ID", GetType(Integer))
  19.         DT.Columns.Add("Name", GetType(String))
  20.  
  21.         For i = 0 To 9
  22.             DT.Rows.Add(i + 1, Chr(i + 65))
  23.         Next
  24.         DGV.DataSource = DT
  25.     End Sub
  26. End Class
  27.  
  28. Public Class Form2
  29.     Private DT As DataTable
  30.     Private Sub Form2_Load(sender As Object, e As EventArgs) Handles MyBase.Load
  31.         DT = DirectCast(Owner, Form1).DGV.DataSource
  32.     End Sub
  33.  
  34.     Private Sub BtnFilter_Click(sender As Object, e As EventArgs) Handles BtnFilter.Click
  35.         If DT IsNot Nothing Then
  36.             DT.DefaultView.RowFilter = TxtFilter.Text
  37.         End If
  38.     End Sub
  39. End Class
Advertisement
Add Comment
Please, Sign In to add comment
Advertisement