Public Class Form1
Inherits System.Windows.Forms.Form
#Region " Windows Form 設計工具產生的程式碼 "
Public Sub New()
MyBase.New()
'此呼叫為 Windows Form 設計工具的必要項。
InitializeComponent()
'在 InitializeComponent() 呼叫之後加入所有的初始設定
End Sub
'Form 覆寫 Dispose 以清除元件清單。
Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
If disposing Then
If Not (components Is Nothing) Then
components.Dispose()
End If
End If
MyBase.Dispose(disposing)
End Sub
'為 Windows Form 設計工具的必要項
Private components As System.ComponentModel.IContainer
'注意: 以下為 Windows Form 設計工具所需的程序
'您可以使用 Windows Form 設計工具進行修改。
'請勿使用程式碼編輯器來修改這些程序。
Friend WithEvents DataGrid1 As System.Windows.Forms.DataGrid
Friend WithEvents Button1 As System.Windows.Forms.Button
Friend WithEvents Button2 As System.Windows.Forms.Button
Friend WithEvents DataGridTableStyle1 As System.Windows.Forms.DataGridTableStyle
Friend WithEvents DataGridTextBoxColumn1 As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents DataGridBoolColumn1 As System.Windows.Forms.DataGridBoolColumn
Friend WithEvents DataGridTableStyle2 As System.Windows.Forms.DataGridTableStyle
Friend WithEvents DataGridTextBoxColumn2 As System.Windows.Forms.DataGridTextBoxColumn
Friend WithEvents DataGridTextBoxColumn3 As System.Windows.Forms.DataGridTextBoxColumn
<System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(Form1))
Me.DataGrid1 = New System.Windows.Forms.DataGrid()
Me.Button1 = New System.Windows.Forms.Button()
Me.Button2 = New System.Windows.Forms.Button()
Me.DataGridTableStyle1 = New System.Windows.Forms.DataGridTableStyle()
Me.DataGridTextBoxColumn1 = New System.Windows.Forms.DataGridTextBoxColumn()
Me.DataGridBoolColumn1 = New System.Windows.Forms.DataGridBoolColumn()
Me.DataGridTableStyle2 = New System.Windows.Forms.DataGridTableStyle()
Me.DataGridTextBoxColumn2 = New System.Windows.Forms.DataGridTextBoxColumn()
Me.DataGridTextBoxColumn3 = New System.Windows.Forms.DataGridTextBoxColumn()
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).BeginInit()
Me.SuspendLayout()
'
'DataGrid1
'
Me.DataGrid1.DataMember = ""
Me.DataGrid1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGrid1.Location = New System.Drawing.Point(16, 24)
Me.DataGrid1.Name = "DataGrid1"
Me.DataGrid1.Size = New System.Drawing.Size(264, 232)
Me.DataGrid1.TabIndex = 0
Me.DataGrid1.TableStyles.AddRange(New System.Windows.Forms.DataGridTableStyle() {Me.DataGridTableStyle1, Me.DataGridTableStyle2})
'
'Button1
'
Me.Button1.Location = New System.Drawing.Point(48, 272)
Me.Button1.Name = "Button1"
Me.Button1.TabIndex = 1
Me.Button1.Text = "Button1"
'
'Button2
'
Me.Button2.Location = New System.Drawing.Point(168, 272)
Me.Button2.Name = "Button2"
Me.Button2.TabIndex = 2
Me.Button2.Text = "Button2"
'
'DataGridTableStyle1
'
Me.DataGridTableStyle1.DataGrid = Me.DataGrid1
Me.DataGridTableStyle1.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn1, Me.DataGridBoolColumn1})
Me.DataGridTableStyle1.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGridTableStyle1.LinkColor = System.Drawing.SystemColors.HotTrack
Me.DataGridTableStyle1.MappingName = "ONE"
'
'DataGridTextBoxColumn1
'
Me.DataGridTextBoxColumn1.Format = ""
Me.DataGridTextBoxColumn1.FormatInfo = Nothing
Me.DataGridTextBoxColumn1.HeaderText = "One"
Me.DataGridTextBoxColumn1.MappingName = "Col1"
'
'DataGridBoolColumn1
'
Me.DataGridBoolColumn1.FalseValue = False
Me.DataGridBoolColumn1.HeaderText = "TWO"
Me.DataGridBoolColumn1.MappingName = "Col2"
Me.DataGridBoolColumn1.NullValue = CType(resources.GetObject("DataGridBoolColumn1.NullValue"), System.DBNull)
Me.DataGridBoolColumn1.TrueValue = True
Me.DataGridBoolColumn1.Width = 50
'
'DataGridTableStyle2
'
Me.DataGridTableStyle2.DataGrid = Me.DataGrid1
Me.DataGridTableStyle2.GridColumnStyles.AddRange(New System.Windows.Forms.DataGridColumnStyle() {Me.DataGridTextBoxColumn2, Me.DataGridTextBoxColumn3})
Me.DataGridTableStyle2.HeaderForeColor = System.Drawing.SystemColors.ControlText
Me.DataGridTableStyle2.MappingName = "TWO"
'
'DataGridTextBoxColumn2
'
Me.DataGridTextBoxColumn2.Format = ""
Me.DataGridTextBoxColumn2.FormatInfo = Nothing
Me.DataGridTextBoxColumn2.HeaderText = "001"
Me.DataGridTextBoxColumn2.MappingName = "Col1"
Me.DataGridTextBoxColumn2.Width = 200
'
'DataGridTextBoxColumn3
'
Me.DataGridTextBoxColumn3.Format = ""
Me.DataGridTextBoxColumn3.FormatInfo = Nothing
Me.DataGridTextBoxColumn3.HeaderText = "002"
Me.DataGridTextBoxColumn3.MappingName = "Col2"
Me.DataGridTextBoxColumn3.Width = 250
'
'Form1
'
Me.AutoScaleBaseSize = New System.Drawing.Size(5, 15)
Me.ClientSize = New System.Drawing.Size(292, 309)
Me.Controls.AddRange(New System.Windows.Forms.Control() {Me.Button2, Me.Button1, Me.DataGrid1})
Me.Name = "Form1"
Me.Text = "Form1"
CType(Me.DataGrid1, System.ComponentModel.ISupportInitialize).EndInit()
Me.ResumeLayout(False)
End Sub
#End Region
Dim tb1 As DataTable
Dim tb2 As DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
tb1 = New DataTable("ONE")
tb2 = New DataTable("TWO")
tb1.Columns.Add(New DataColumn("Col1", GetType(String)))
tb1.Columns.Add(New DataColumn("Col2", GetType(Boolean)))
Dim dr As DataRow
dr = tb1.NewRow
dr.Item("Col1") = "ABCD"
dr.Item("Col2") = False
tb1.Rows.Add(dr)
dr = tb1.NewRow
dr.Item("Col1") = "ABCDER"
dr.Item("Col2") = True
tb1.Rows.Add(dr)
tb2.Columns.Add(New DataColumn("Col1", GetType(String)))
tb2.Columns.Add(New DataColumn("Col2", GetType(String)))
dr = tb2.NewRow
dr.Item("Col1") = "ABCD"
dr.Item("Col2") = "KKKKKKKK"
tb2.Rows.Add(dr)
dr = tb2.NewRow
dr.Item("Col1") = "ABCDdsfdds"
dr.Item("Col2") = "KKKKKKKKadsfasdf"
tb2.Rows.Add(dr)
End Sub
Private Sub Button1_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button1.Click
DataGrid1.DataSource = tb1
End Sub
Private Sub Button2_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles Button2.Click
DataGrid1.DataSource = tb2
End Sub
End Class