• 设为首页
  • 点击收藏
  • 手机版
    手机扫一扫访问
    迪恩网络手机版
  • 关注官方公众号
    微信扫一扫关注
    公众号

VB.NET BindingList<T>类代码示例

原作者: [db:作者] 来自: [db:来源] 收藏 邀请

本文整理汇总了VB.NET中System.ComponentModel.BindingList<T>的典型用法代码示例。如果您正苦于以下问题:VB.NET BindingList<T>类的具体用法?VB.NET BindingList<T>怎么用?VB.NET BindingList<T>使用的例子?那么恭喜您, 这里精选的类代码示例或许可以为您提供帮助。



在下文中一共展示了BindingList<T>类的1个代码示例,这些例子默认根据受欢迎程度排序。您可以为喜欢或者感觉有用的代码点赞,您的评价将有助于我们的系统推荐出更棒的VB.NET代码示例。

示例1: Form1

Option Explicit On
Option Strict On
Imports System.Collections.Generic
Imports System.ComponentModel
Imports System.Drawing
Imports System.Text
Imports System.Windows.Forms

Class Form1
    Inherits Form

    Private textBox2 As TextBox
    Private listBox1 As ListBox
    Private WithEvents button1 As Button
    Private textBox1 As TextBox
    Private randomNumber As New Random()

    Public Sub New()
        Me.AutoScaleMode = System.Windows.Forms.AutoScaleMode.Font
        Me.textBox1 = New System.Windows.Forms.TextBox()
        Me.textBox2 = New System.Windows.Forms.TextBox()
        Me.listBox1 = New System.Windows.Forms.ListBox()
        Me.button1 = New System.Windows.Forms.Button()
        Me.textBox1.Location = New System.Drawing.Point(169, 26)
        Me.textBox1.Size = New System.Drawing.Size(100, 20)
        Me.textBox1.Text = "Bracket"
        Me.textBox2.Location = New System.Drawing.Point(169, 57)
        Me.textBox2.ReadOnly = True
        Me.textBox2.Size = New System.Drawing.Size(100, 20)
        Me.textBox2.Text = "4343"
        Me.listBox1.FormattingEnabled = True
        Me.listBox1.Location = New System.Drawing.Point(12, 12)
        Me.listBox1.Size = New System.Drawing.Size(120, 95)
        Me.button1.Location = New System.Drawing.Point(180, 83)
        Me.button1.Size = New System.Drawing.Size(75, 23)
        Me.button1.Text = "Add New Item"
        Me.ClientSize = New System.Drawing.Size(292, 266)
        Me.Controls.Add(Me.button1)
        Me.Controls.Add(Me.listBox1)
        Me.Controls.Add(Me.textBox2)
        Me.Controls.Add(Me.textBox1)
        Me.Text = "Parts Form"
        AddHandler Me.Load, AddressOf Form1_Load

    End Sub

    Sub Form1_Load(ByVal sender As Object, ByVal e As EventArgs)
        InitializeListOfParts()
        listBox1.DataSource = listOfParts
        listBox1.DisplayMember = "PartName"
    End Sub

    ' Declare a new BindingListOfT with the Part business object.
    Private WithEvents listOfParts As BindingList(Of Part)

    Private Sub InitializeListOfParts()

        ' Create the new BindingList of Part type.
        listOfParts = New BindingList(Of Part)

        ' Allow new parts to be added, but not removed once committed.        
        listOfParts.AllowNew = True
        listOfParts.AllowRemove = False

        ' Raise ListChanged events when new parts are added.
        listOfParts.RaiseListChangedEvents = True

        ' Do not allow parts to be edited.
        listOfParts.AllowEdit = False

        ' Add a couple of parts to the list.
        listOfParts.Add(New Part("Widget", 1234))
        listOfParts.Add(New Part("Gadget", 5647))

    End Sub

    ' Create a new part from the text in the two text boxes.
    Private Sub listOfParts_AddingNew(ByVal sender As Object, _
        ByVal e As AddingNewEventArgs) Handles listOfParts.AddingNew
        e.NewObject = New Part(textBox1.Text, Integer.Parse(textBox2.Text))

    End Sub


    ' Add the new part unless the part number contains
    ' spaces. In that case cancel the add.
    Private Sub button1_Click(ByVal sender As Object, _
        ByVal e As EventArgs) Handles button1.Click

        Dim newPart As Part = listOfParts.AddNew()

        If newPart.PartName.Contains(" ") Then
            MessageBox.Show("Part names cannot contain spaces.")
            listOfParts.CancelNew(listOfParts.IndexOf(newPart))
        Else
            textBox2.Text = randomNumber.Next(9999).ToString()
            textBox1.Text = "Enter part name"
        End If

    End Sub

    <STAThread()> _
    Shared Sub Main()
        Application.EnableVisualStyles()
        Application.Run(New Form1())

    End Sub
End Class

' A simple business object for example purposes.
Public Class Part
    Private name As String
    Private number As Integer

    Public Sub New()
    End Sub

    Public Sub New(ByVal nameForPart As String, _
        ByVal numberForPart As Integer)
        PartName = nameForPart
        PartNumber = numberForPart

    End Sub


    Public Property PartName() As String
        Get
            Return name
        End Get
        Set(ByVal value As String)
            name = Value
        End Set
    End Property

    Public Property PartNumber() As Integer
        Get
            Return number
        End Get
        Set(ByVal value As Integer)
            number = Value
        End Set
    End Property
End Class
开发者ID:VB.NET开发者,项目名称:System.ComponentModel,代码行数:143,代码来源:BindingList



注:本文中的System.ComponentModel.BindingList<T>类示例整理自Github/MSDocs等源码及文档管理平台,相关代码片段筛选自各路编程大神贡献的开源项目,源码版权归原作者所有,传播和使用请参考对应项目的License;未经允许,请勿转载。


鲜花

握手

雷人

路过

鸡蛋
该文章已有0人参与评论

请发表评论

全部评论

专题导读
上一篇:
VB.NET ByteConverter类代码示例发布时间:2022-05-24
下一篇:
VB.NET CodeTypeOfExpression类代码示例发布时间:2022-05-24
热门推荐
热门话题
阅读排行榜

扫描微信二维码

查看手机版网站

随时了解更新最新资讯

139-2527-9053

在线客服(服务时间 9:00~18:00)

在线QQ客服
地址:深圳市南山区西丽大学城创智工业园
电邮:jeky_zhao#qq.com
移动电话:139-2527-9053

Powered by 互联科技 X3.4© 2001-2213 极客世界.|Sitemap