当前位置: 首页>>代码示例>>VB.NET>>正文


VB.NET ListControl.DisplayMember属性代码示例

本文整理汇总了VB.NET中System.Windows.Forms.ListControl.DisplayMember属性的典型用法代码示例。如果您正苦于以下问题:VB.NET ListControl.DisplayMember属性的具体用法?VB.NET ListControl.DisplayMember怎么用?VB.NET ListControl.DisplayMember使用的例子?那么恭喜您, 这里精选的属性代码示例或许可以为您提供帮助。您也可以进一步了解该属性所在System.Windows.Forms.ListControl的用法示例。


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

示例1: ListBoxSample3

' 导入命名空间
Imports System.Windows.Forms
Imports System.Drawing
Imports System.Collections

Public Class ListBoxSample3
    Inherits Form

    Private ListBox1 As New ListBox()
    Private label1 As New Label()
    Private textBox1 As New TextBox()

    <STAThread()> _
    Shared Sub Main()
        Application.Run(New ListBoxSample3())
    End Sub

    Public Sub New()
        Me.ClientSize = New Size(307, 206)
        Me.Text = "ListBox Sample3"

        ListBox1.Location = New Point(54, 16)
        ListBox1.Name = "ListBox1"
        ListBox1.Size = New Size(240, 130)

        label1.Location = New Point(14, 150)
        label1.Name = "label1"
        label1.Size = New Size(40, 24)
        label1.Text = "Value"

        textBox1.Location = New Point(54, 150)
        textBox1.Name = "textBox1"
        textBox1.Size = New Size(240, 24)

        Me.Controls.AddRange(New Control() {ListBox1, label1, textBox1})

        ' Populate the list box using an array as DataSource. 
        Dim USStates As New ArrayList()
        USStates.Add(New USState("Alabama", "AL"))
        USStates.Add(New USState("Washington", "WA"))
        USStates.Add(New USState("West Virginia", "WV"))
        USStates.Add(New USState("Wisconsin", "WI"))
        USStates.Add(New USState("Wyoming", "WY"))
        ListBox1.DataSource = USStates

        ' Set the long name as the property to be displayed and the short
        ' name as the value to be returned when a row is selected.  Here
        ' these are properties; if we were binding to a database table or
        ' query these could be column names.
        ListBox1.DisplayMember = "LongName"
        ListBox1.ValueMember = "ShortName"

        ' Bind the SelectedValueChanged event to our handler for it.
        AddHandler ListBox1.SelectedValueChanged, AddressOf ListBox1_SelectedValueChanged

        ' Ensure the form opens with no rows selected.
        ListBox1.ClearSelected()
    End Sub

    Private Sub InitializeComponent()
    End Sub

    Private Sub ListBox1_SelectedValueChanged(ByVal sender As Object, ByVal e As EventArgs)
        If ListBox1.SelectedIndex <> -1 Then
            textBox1.Text = ListBox1.SelectedValue.ToString()
            ' If we also wanted to get the displayed text we could use
            ' the SelectedItem item property:
            ' Dim s = CType(ListBox1.SelectedItem, USState).LongName
        End If
    End Sub
End Class

Public Class USState
    Private myShortName As String
    Private myLongName As String

    Public Sub New(ByVal strLongName As String, ByVal strShortName As String)
        Me.myShortName = strShortName
        Me.myLongName = strLongName
    End Sub

    Public ReadOnly Property ShortName() As String
        Get
            Return myShortName
        End Get
    End Property

    Public ReadOnly Property LongName() As String
        Get
            Return myLongName
        End Get
    End Property

End Class
开发者ID:VB.NET开发者,项目名称:System.Windows.Forms,代码行数:94,代码来源:ListControl.DisplayMember


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