WinForm设计之UBindingNavigator

王朝system·作者佚名  2006-11-28
窄屏简体版  字體: |||超大  

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

效果图:

 
 
 
免责声明:本文为网络用户发布,其观点仅代表作者个人观点,与本站无关,本站仅提供信息存储服务。文中陈述内容未经本站证实,其真实性、完整性、及时性本站不作任何保证或承诺,请读者仅作参考,并请自行核实相关内容。
 
 
© 2005- 王朝網路 版權所有 導航