Author:水如烟
代码见应用类代码:LzmTW.uSystem.uWindows.uForms + uBindingNavigator
示意图:
示例代码:
Imports System.Reflection
Public Class Form1
Private gNorthwind As New Northind
Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
Me.UBindingNavigator1.SourceManager.Add(GetItem("Customers"))
Me.UBindingNavigator1.SourceManager.Add(GetItem("Employees"))
Dim t As New DataTable("测试一")
Dim b As New DataTable("测试二")
Dim c As New DataTable
With t
.Columns.Add("列一")
.Columns.Add("列二")
.Rows.Add(New Object() {"1", "张三"})
.Rows.Add(New Object() {"2", "李四"})
.Rows.Add(New Object() {"3", "王五"})
.Rows.Add(New Object() {"4", "钱六"})
.AcceptChanges()
End With
With b
.Columns.Add("列三")
.Columns.Add("列四")
.Rows.Add(New Object() {"1", "张三"})
.Rows.Add(New Object() {"2", "李四"})
.Rows.Add(New Object() {"3", "王五"})
.Rows.Add(New Object() {"4", "钱六"})
.Rows.Add(New Object() {"5", "张三"})
.Rows.Add(New Object() {"6", "李四"})
.Rows.Add(New Object() {"7", "王五"})
.Rows.Add(New Object() {"8", "钱六"})
.AcceptChanges()
End With
Dim m As New LzmTW.uSystem.uWindows.uForms.uMainForm.Menu.MenuManager
m.GetDefault()
m.UpdateTo(c)
With Me.UBindingNavigator1.SourceManager
.Add(New LzmTW.uSystem.uWindows.uForms.uBindingNavigator.TableInformation(t, t.TableName))
.Add(New LzmTW.uSystem.uWindows.uForms.uBindingNavigator.TableInformation(b, b.TableName))
.Add(New LzmTW.uSystem.uWindows.uForms.uBindingNavigator.TableInformation(c, c.TableName))
End With
End Sub
Private Function GetItem(ByVal table As String) As LzmTW.uSystem.uWindows.uForms.uBindingNavigator.TableInformation
Dim mResult As New LzmTW.uSystem.uWindows.uForms.uBindingNavigator.TableInformation
With mResult
.DataAdapter = gNorthwind.CreateAdapter(table)
.KeyName = table
End With
Return mResult
End Function
End Class
Public Class Northind
Private gLoginInformation As New LzmTW.uSystem.uData.uSql.LoginInformations
Sub New()
gLoginInformation.Database = "Northwind"
End Sub
Public Function CreateAdapter(ByVal table As String) As SqlClient.SqlDataAdapter
Dim ad As New SqlClient.SqlDataAdapter(Me.GetSelectCommand(table))
Dim cb As New SqlClient.SqlCommandBuilder(ad)
Return ad
End Function
Private Function GetSelectCommand(ByVal table As String) As SqlClient.SqlCommand
Return New SqlClient.SqlCommand(String.Format("SELECT * FROM {0}", table), Me.GetConnection)
End Function
Private Function GetConnection() As SqlClient.SqlConnection
Return New SqlClient.SqlConnection(Me.gLoginInformation.ConnectionStringBuilder.ConnectionString)
End Function
End Class
效果图: