|
分類:[VB.NET]
分類:[VB.NET]
プロジェクト間のデータの受け渡しで質問させてもらって解決したのですが、これ以外にいい書き方(今は無理やり表示させてるようない気がして・・・)があったら教えてください。 <下記コード> frm表示 ↓Private Sub btn検索_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btn検索.Click Dim f As WindowsApplication1.frm検索 = New WindowsApplication1.frm検索 If f.ShowDialog = DialogResult.OK Then txtID.Text = f.GetValue1 txt名前.Text = f.GetValue2 txt住所.Text = f.GetValue3
End If f.Dispose() End Sub
========================================================================= frm検索 ↓ Private m_MasterDt As DataTable
Private Sub frm検索_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load Dim sqlCon As SqlClient.SqlConnection Dim cStyle(2) As DataGridColumnStyle Dim tStyle As DataGridTableStyle Dim gTextCol1 As DataGridTextBoxColumn Dim gTextBox1 As DataGridTextBox Dim a As String
Try sqlCon = New SqlClient.SqlConnection( _ "Data Source = localhost;PersistSecurityInfo=False" _ + ";Integrated Security=SSPI;database=Yuukari")
Dim dSet As DataSet = New DataSet("情報") Dim dAdp As SqlClient.SqlDataAdapter
sqlCon.Open()
dAdp = New SqlClient.SqlDataAdapter( _ "SELECT * FROM T_情報", sqlCon) dAdp.Fill(dSet, "情報")
Me.m_MasterDt = dSet.Tables("情報") tStyle = New DataGridTableStyle tStyle.MappingName = "情報" DataGrid1.TableStyles.Add(tStyle)
cStyle(0) = New DataGridTextBoxColumn cStyle(0).MappingName = "ID" cStyle(0).HeaderText = "ID" cStyle(0).Width = 50 tStyle.GridColumnStyles.Add(cStyle(0))
cStyle(1) = New DataGridTextBoxColumn cStyle(1).MappingName = "名前" cStyle(1).HeaderText = "名前" cStyle(1).Width = 100 tStyle.GridColumnStyles.Add(cStyle(1))
cStyle(2) = New DataGridTextBoxColumn cStyle(2).MappingName = "住所" cStyle(2).HeaderText = "住所" cStyle(2).Width = 200 tStyle.GridColumnStyles.Add(cStyle(2))
'gTextCol1 = tStyle.GridColumnStyles(0) 'gTextBox1 = gTextCol1.TextBox
'AddHandler gTextBox1.TextChanged, AddressOf btnOK_Click 'a = DataGrid1.Item(DataGrid1.CurrentRowIndex, 0)
DataGrid1.CaptionText = "情報" DataGrid1.CaptionForeColor = Color.Red DataGrid1.CaptionBackColor = Color.White DataGrid1.DataSource = Me.m_MasterDt
Catch ex As Exception MessageBox.Show(ex.Message) End Try sqlCon.Close() End Sub
Private Sub btnOK_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles btnOK.Click Me.DialogResult = DialogResult.OK Me.Close() End Sub Public Function GetValue1() As String Dim a As String a = DataGrid1.Item(DataGrid1.CurrentRowIndex, 0) Return a
End Function Public Function GetValue2() As String Dim b As String b = DataGrid1.Item(DataGrid1.CurrentRowIndex, 1) Return b
End Function Public Function GetValue3() As String Dim c As String c = DataGrid1.Item(DataGrid1.CurrentRowIndex, 2) Return c End Function
=========================================================================- このようにretuenでのやりとりや、DataGridからのデータの出し方が無理やりっぽいのです。 <動き> @frm表示で検索ボタンを押す。 Afrm検索でDataGridにデータベースにあるデータ取得し、列を選択してOKボタン押す。 Bfrm表示が表示され、txtID,txt名前,txt住所にそれぞれ表示される。 以上が簡単なうごきです、何かアドバイス、変更点があったらご伝授よろしくお願いします。
|