Begin MSDN:
要使 Windows 窗体数据绑定成为可能,必须有数据提供程序和使用者。
从提供程序这一方最容易接近 Windows 窗体数据绑定的结构。
绑定一个 Windows 窗体及其控件的开始在于数据的“提供程序”。
不仅可以绑定到传统的数据源,而且可以绑定到几乎任何包含数据的结构。
实现 IList 接口的数组、集合或者 ADO .NET 中的数据结构之一都是合适的数据源。
Windows 窗体控件绑定到的任何数据源将都具有一个关联的 CurrencyManager 对象。
CurrencyManager 对象跟踪位置,另外监控对该数据源的绑定。
对于当前绑定到的每个离散数据源,在窗体上都有一个 CurrencyManager 对象。
如果窗体上的所有控件都绑定到一个源(例如,如果几个 TextBox控件绑定到同一数据表),
那么它们将共享同一个 CurrencyManager。但是,有时窗体上的控件将绑定到不同的源。
在这种情况下,窗体上有多个 CurrencyManager 对象,每个都跟踪控件正在使用哪个记录或数据元素。
另外,每个 Windows 窗体都有一个 BindingContext 对象。
BindingContext 对象跟踪窗体上的所有 CurrencyManager 对象。
因此,任何具有数据绑定控件的 Windows 窗体都至少有一个跟踪一个
(或多个)CurrencyManager 对象的 BindingContext 对象,而每个
CurrencyManager 对象又跟踪一个数据源。如果使用容器控件,
如 GroupBox、Panel 或 TabControl 来包含数据绑定控件,
则可以只为该容器控件及其控件创建一个 BindingContext。这使窗体的各个部分都由它
自己的 CurrencyManager 对象来管理。
End MSDN

XNavBar Code:(100%原创)

Public Class XNavBarClass XNavBar
    Inherits System.Windows.Forms.UserControl

    Private ug As Windows.Forms.DataGrid


#Region " Windows Form Designer generated code "

    Public Sub New()Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'UserControl1 overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose()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

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents btnFirst As System.Windows.Forms.Button
    Friend WithEvents btnPrevious As System.Windows.Forms.Button
    Friend WithEvents btnNext As System.Windows.Forms.Button
    Friend WithEvents btnLast As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()Sub InitializeComponent()
        Dim resources As System.Resources.ResourceManager = New System.Resources.ResourceManager(GetType(XNavBar))
        Me.btnLast = New System.Windows.Forms.Button
        Me.btnNext = New System.Windows.Forms.Button
        Me.btnPrevious = New System.Windows.Forms.Button
        Me.btnFirst = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'btnLast
        '
        Me.btnLast.BackColor = System.Drawing.SystemColors.Control
        Me.btnLast.ForeColor = System.Drawing.SystemColors.Control
        Me.btnLast.Image = CType(resources.GetObject("btnLast.Image"), System.Drawing.Image)
        Me.btnLast.Location = New System.Drawing.Point(72, 0)
        Me.btnLast.Name = "btnLast"
        Me.btnLast.Size = New System.Drawing.Size(24, 24)
        Me.btnLast.TabIndex = 3
        '
        'btnNext
        '
        Me.btnNext.BackColor = System.Drawing.SystemColors.Control
        Me.btnNext.ForeColor = System.Drawing.SystemColors.Control
        Me.btnNext.Image = CType(resources.GetObject("btnNext.Image"), System.Drawing.Image)
        Me.btnNext.Location = New System.Drawing.Point(48, 0)
        Me.btnNext.Name = "btnNext"
        Me.btnNext.Size = New System.Drawing.Size(24, 24)
        Me.btnNext.TabIndex = 2
        '
        'btnPrevious
        '
        Me.btnPrevious.BackColor = System.Drawing.SystemColors.Control
        Me.btnPrevious.ForeColor = System.Drawing.SystemColors.ControlLight
        Me.btnPrevious.Image = CType(resources.GetObject("btnPrevious.Image"), System.Drawing.Image)
        Me.btnPrevious.Location = New System.Drawing.Point(24, 0)
        Me.btnPrevious.Name = "btnPrevious"
        Me.btnPrevious.Size = New System.Drawing.Size(24, 24)
        Me.btnPrevious.TabIndex = 1
        '
        'btnFirst
        '
        Me.btnFirst.BackColor = System.Drawing.SystemColors.Control
        Me.btnFirst.ForeColor = System.Drawing.SystemColors.Control
        Me.btnFirst.Image = CType(resources.GetObject("btnFirst.Image"), System.Drawing.Image)
        Me.btnFirst.Location = New System.Drawing.Point(0, 0)
        Me.btnFirst.Name = "btnFirst"
        Me.btnFirst.Size = New System.Drawing.Size(24, 24)
        Me.btnFirst.TabIndex = 0
        '
        'XNavBar
        '
        Me.BackColor = System.Drawing.SystemColors.Control
        Me.Controls.Add(Me.btnLast)
        Me.Controls.Add(Me.btnPrevious)
        Me.Controls.Add(Me.btnFirst)
        Me.Controls.Add(Me.btnNext)
        Me.Name = "XNavBar"
        Me.Size = New System.Drawing.Size(96, 24)
        Me.ResumeLayout(False)

    End Sub

#End Region

#Region "Property code"

    Public Property NBFirst()Property NBFirst() As Boolean
        Get
            Return btnFirst.Visible
        End Get
        Set(ByVal Value As Boolean)
            btnFirst.Visible = Value
            ProecssSize()
        End Set
    End Property

    Public Property NBPrior()Property NBPrior() As Boolean
        Get
            Return btnPrevious.Visible
        End Get
        Set(ByVal Value As Boolean)
            btnPrevious.Visible = Value
            ProecssSize()
        End Set
    End Property

    Public Property NBLast()Property NBLast() As Boolean
        Get
            Return btnLast.Visible
        End Get
        Set(ByVal Value As Boolean)
            btnLast.Visible = Value
            ProecssSize()
        End Set
    End Property

    Public Property NBNext()Property NBNext() As Boolean
        Get
            Return btnNext.Visible
        End Get
        Set(ByVal Value As Boolean)
            btnNext.Visible = Value
            ProecssSize()
        End Set
    End Property

    Public Property DataGrid()Property DataGrid() As Windows.Forms.DataGrid
        Get
            Return ug
        End Get
        Set(ByVal Value As Windows.Forms.DataGrid)
            ug = Value
            If Value Is Nothing Then
                btnFirst.Enabled = False
                btnPrevious.Enabled = False
                btnLast.Enabled = False
                btnNext.Enabled = False
            Else
                btnFirst.Enabled = True
                btnPrevious.Enabled = True
                btnLast.Enabled = True
                btnNext.Enabled = True
            End If

        End Set
    End Property

#End Region

#Region "System.EventArgs code"
    Private Sub NavigateBar_Resize()Sub NavigateBar_Resize(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Resize

        If Me.Width < 96 Then Me.Width = 96
        If Me.Height < 24 Then Me.Height = 24
        Dim Ar As New ArrayList
        Ar.Clear()
        Ar.Add(btnFirst)
        Ar.Add(btnPrevious)
        Ar.Add(btnNext)
        Ar.Add(btnLast)
        Dim c As Control
        Dim I, J As Integer
        Dim TotalWidth As Integer = Me.Width
        For Each c In Ar
            Dim bt As Button
            bt = CType(c, Button)
            If bt.Visible Then
                I = I + 1
            End If
        Next
        Dim sWidth As Integer = TotalWidth / I
        For Each c In Ar
            Dim bt As Button
            bt = CType(c, Button)
            If bt.Visible Then
                bt.Left = J * sWidth
                bt.Width = sWidth
                bt.Height = Me.Height
                J = J + 1
            End If
        Next
        Ar = Nothing

    End Sub

    Private Sub NavigateBar_Load()Sub NavigateBar_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        RefreshNavigationBar()
    End Sub


    Private Sub btnFirst_Click()Sub btnFirst_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnFirst.Click
        MoveDataSourceByNavigation(ug, "tFirst")
        RefreshNavigationBar()
    End Sub

    Private Sub btnPrevious_Click()Sub btnPrevious_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrevious.Click
        MoveDataSourceByNavigation(ug, "tPrevious")
        RefreshNavigationBar()
    End Sub

    Private Sub btnNext_Click()Sub btnNext_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnNext.Click
        MoveDataSourceByNavigation(ug, "tNext")
        RefreshNavigationBar()
    End Sub

    Private Sub btnLast_Click()Sub btnLast_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnLast.Click
        MoveDataSourceByNavigation(ug, "tLast")
        RefreshNavigationBar()
    End Sub

#End Region

#Region "customer mothed code"
    Private Sub ProecssSize()Sub ProecssSize()
        Dim Ar As New ArrayList
        Ar.Clear()
        Ar.Add(btnFirst)
        Ar.Add(btnPrevious)
        Ar.Add(btnNext)
        Ar.Add(btnLast)
        Dim c As Control
        Dim I, J As Integer
        Dim TotalWidth As Integer = Me.Width
        For Each c In Ar
            Dim bt As Button
            bt = CType(c, Button)
            If bt.Visible Then
                I = I + 1
            End If
        Next
        Dim sWidth As Integer = TotalWidth / I
        Me.Width = I * sWidth
        Ar = Nothing
    End Sub

    Private Function GetCurrencyManager()Function GetCurrencyManager(ByVal datasource As Object) As CurrencyManager
        Dim cmg As CurrencyManager

        cmg = Me.BindingContext.Item(datasource)
        If IsNothing(cmg) Then Exit Function
        Dim m As Integer = cmg.Count
        If m <= 1 Then
            Exit Function
        End If
        Return cmg
    End Function

    Private Sub MoveDataSourceByNavigation()Sub MoveDataSourceByNavigation(ByRef ug As Windows.Forms.DataGrid, ByVal sKey As String)
        sKey = Trim(sKey)
        If sKey = "" Then Exit Sub
        If ug Is Nothing Then
            MessageBox.Show("No set UltraGrid on Navigation bar!", "NavigationBar", MessageBoxButtons.OK, MessageBoxIcon.Stop, MessageBoxDefaultButton.Button1)
            Exit Sub
        End If
        Dim cmg As CurrencyManager
        cmg = GetCurrencyManager(ug.DataSource)
        If cmg Is Nothing Then Exit Sub

        Dim Position, m As Integer
        m = cmg.Count
        Position = cmg.Position

        Select Case sKey
            Case "tFirst"
                Position = 0
                If cmg.Position <> Position Then
                    cmg.Position = Position
                End If
            Case "tLast"
                Position = m - 1
                If cmg.Position <> Position Then
                    cmg.Position = Position
                End If
            Case "tPrevious"
                Position = Position - 1
                If Position < 0 Then Position = 0
                If cmg.Position <> Position Then
                    cmg.Position = Position
                End If
            Case "tNext"
                Position = Position + 1
                If Position > (m - 1) Then Position = m - 1
                If cmg.Position <> Position Then
                    cmg.Position = Position
                End If
        End Select

    End Sub

#End Region

#Region "RefreshNavigationBar mothed code"
    Public Sub RefreshNavigationBar()Sub RefreshNavigationBar()
        If (ug Is Nothing) Then
            btnFirst.Enabled = False
            btnPrevious.Enabled = False
            btnLast.Enabled = False
            btnNext.Enabled = False
            Exit Sub
        End If
        Dim cmg As CurrencyManager
        If ug.DataSource Is Nothing Then Exit Sub
        cmg = GetCurrencyManager(ug.DataSource)
        If cmg Is Nothing Then Exit Sub

        Dim Position, m As Integer
        m = cmg.Count
        Position = cmg.Position


        If m = 0 Then Exit Sub

        Select Case Position
            Case 0
                btnFirst.Enabled = False
                btnPrevious.Enabled = False
                btnLast.Enabled = True
                btnNext.Enabled = True
            Case m - 1
                btnLast.Enabled = False
                btnNext.Enabled = False
                btnFirst.Enabled = True
                btnPrevious.Enabled = True
            Case Else
                btnLast.Enabled = True
                btnNext.Enabled = True
                btnFirst.Enabled = True
                btnPrevious.Enabled = True
        End Select
    End Sub
#End Region

End Class



100% .NET Control_使用CurrencyManager 创建一个导航条来控制DatagGrid的XNavBar控件(VB.NET)....相关推荐

  1. 从零开始学PowerShell(8)创建一个进度条

    我相信不少人会遇到这类情况,通常在执行一些大批量操作时,代码正在后台持续执行,你又没有为每个细节设置详尽的输出的话,你也不知道到底是脚本卡死了还是正在运行,因为没有任何响应反馈. 应对这种情况,要是我 ...

  2. 跨线程操作无效:从创建该线程的线程以外的线程访问控件

    我有一个场景. (Windows窗体,C#.. NET) 有一个主窗体可以承载一些用户控件. 用户控件执行一些繁重的数据操作,因此,如果我直接调用UserControl_Load方法,则UI在加载方法 ...

  3. android tv 开发布局,Android TV开发总结(七)构建一个TV app中的剧集列表控件

    前言:剧集类控件,在TV app中非常常见,今天将介绍构建一个TV app中的剧集列表控件,此控件上传到我的Github:https://github.com/hejunlin2013/Episode ...

  4. 通过Lua代码创建一个Cube,并实现控制行走

    //创建一个Cube GameObject = UnityEngine.GameObject Input = UnityEngine.Input Time = UnityEngine.Time Tra ...

  5. 100% .NET Control_自动完成Combobox的XComBo控件(VB.NET)

    其实这类的文章在国外的技术网站上也有很多,但是都没有实现combobox的自动下拉. 在这里实现了自动下拉. 在这里我把combobox做成了一个控件(XComBo)来实现功能.它从ComboBox, ...

  6. 一个Demo让你掌握所有的android控件

    注:这个例子来自"安卓巴士",仅在此学习,阅读      下面给出实现各个组件的源代码: 1.下拉框实现--Spinner package com.cellcom;import j ...

  7. 一个Demo学会用Android兼容包新控件

    2019独角兽企业重金招聘Python工程师标准>>> 前言 伟大的Google为Android推出了一系列的兼容包,最新的就是Design Support Library了,这里我 ...

  8. 一个简单的自定义多附件上传控件

    在网上提供的都是生成多个上传控件的代码,但大家可以看看21cn,163那里的多附件上传是不是比那些只是生成多个上传控件的界面美观很多呢??      现在就开始做一个类似21CN那样的上传的.先看看我 ...

  9. android组合控件的焦点,撸一个简单的TV版焦点控制的日历控件

    1.效果 最近需求要一个遥控控制的日历控件,找了半天没找到轮子,就自己撸一个,先看效果图: 效果图.gif 2.XML属性,所有属性默认为效果图 calender_textSize:星期和日期的字体大 ...

最新文章

  1. devstack安装OpenStack Pike版本 (OVN+VLAN)
  2. 个人专著推荐1:Red Hat Linux 9实务自学手册(含光盘)
  3. 网络知识:路由器要不要每天重启?很多人都做错了,难怪网速慢
  4. 新手学习C语言编程的8个致命错误,你中招了吗?
  5. 深入分析Flex [Bindable] (总结)
  6. 硬解析优化_72最近一次现场生产系统优化的成果与开发建议
  7. C++语言基础 —— STL —— 容器与迭代器 —— pair
  8. switch 是如何支持 String 的?为什么不支持 long?
  9. Runtime中神奇的exec方法
  10. 架构之美阅读笔记06
  11. 文本区 JTextArea 的使用
  12. 帆软:像阿甘一样,奔跑在商业智能的赛道上!
  13. Oracle怎么查看离散任务,Oracle ERP操作手册
  14. skyline 系列 1 - 简介、下载
  15. AlphaFold2: Highly accurate protein structure prediction with AlphaFold笔记
  16. 《弃子长安》第三章 月下魅影
  17. 算法与数据结构+LeetCode题解-Js版
  18. 微信公众号推文发布方法(内涵详细步骤)
  19. 解决Couldn‘t determine repo type for URL
  20. 微信小程序登陆凭证校验出现{errcode:40029,errmsg:invalid code, hints: [ req_id: weh8ka0297hc58 ]}

热门文章

  1. css中display设置为table、table-row、table-cell后的作用及其注意点
  2. 实验六 快速生成树配置
  3. swiper超出部分出现滚动条
  4. Lucene源代码学习之 PackedInts
  5. 《算法导论》中parallel for 的时间复杂度
  6. Aveiconifier是一个非常实用方便的制作ico格式文件的小工具~
  7. 基于BitBox的Wormhole SDK 已迭代至1.0.0版本
  8. MySQL之单表查询
  9. .net分布式系统架构的思路
  10. TYVJ P1053 字符串的展开 Label:字符 水