フォームにコントロールとBindingSource、BindingNavigatorを配置します。
Public Class Form1 Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load 'サンプルデータテーブル Dim dt As New DataTable dt.Columns.Add("商品CD", Type.GetType("System.String")) dt.Columns.Add("商品名", Type.GetType("System.String")) dt.Columns.Add("単価", Type.GetType("System.Double")) For i = 1 To 20 Dim nr As DataRow = dt.NewRow nr("商品CD") = i.ToString("000") nr("商品名") = "商品" & i.ToString("000") nr("単価") = i * 100 dt.Rows.Add(nr) Next 'BindingSource1のDataSourceを設定 Me.BindingSource1.DataSource = dt 'BindingSource1をBindingNavigator1と連結 Me.BindingNavigator1.BindingSource = Me.BindingSource1 'BindingSource1を各TextBoxと連結 Me.TextBox1.DataBindings.Add(New Binding("Text", Me.BindingSource1, "商品CD")) Me.TextBox2.DataBindings.Add(New Binding("Text", Me.BindingSource1, "商品名")) Me.TextBox3.DataBindings.Add(New Binding("Text", Me.BindingSource1, "単価")) 'BindingSource1をDataGridView1と連結 Me.DataGridView1.DataSource = Me.BindingSource1 End Sub End Class
実行結果 |
0 件のコメント:
コメントを投稿