フォーム間連携
by achi on Nov.25, 2008, under VB.NETテクニック
データグリッドへ表示した列の内容を別のフォームへ渡す。
渡す側のフォーム(データグリッド表示後)
Public Form4 As New Form4
Public MeArray As New ArrayList
Public Sub New(ByVal fr As Form4)
MyBase.New()
Form4 = fr
InitializeComponent()
End Sub
Private Sub myDataGrid_DoubleClick(ByVal sender As Object, ByVal e As System.EventArgs) Handles DataGrid1.CurrentCellChanged
Const RowRule As Integer = 18 ‘RowCount固定している。実際にはTable.Rows.Count - 1 など
Dim cm As CurrencyManager = CType(DataGrid1.BindingContext(DataGrid1.DataSource, DataGrid1.DataMember), CurrencyManager)
Dim dr As DataRow = CType(cm.Current, DataRowView).Row
For i As Integer = 0 To RowRule
MeArray.Add(dr.ItemArray(i))
Next
If Form4 Is Nothing = False Then
Form4.OurArray = Me.MeArray
End If
Form4.Show()
Me.Hide()
End Sub
受け取り側のフォーム
‘Form3の配列を取得
Private Form3 As Form3
Private mHensu As New ArrayList
Public Property OurArray() As ArrayList
Get
Return mHensu
End Get
Set(ByVal Value As ArrayList)
For i As Integer = 0 To 18 ‘行の項目数を固定しているため
mHensu.Add(Value(i))
Next
End Set
End Property
Leave a Reply
*----* Note : *----*
Please write only in Japanese or English.
If you will post any other languages, we'll mark them as spam.
And also if a linked URI in your comments, I do not approve.
*----*----*
You must be logged in to post a comment.