Wednesday, October 10, 2012

Combobox binding in VB.NET using List(Of T)


Public Class Salutation

    Sub New()
        ' TODO: Complete member initialization
    End Sub

    Public Function GetAll() As List(Of String)
        Dim Salutations As New List(Of String)
        Salutations.Add("Select")
        Salutations.Add("Mr")
        Salutations.Add("Mrs")
        Salutations.Add("Miss")
        Salutations.Add("Ms")
        Salutations.Add("Dr")

        Return Salutations
    End Function

    Public Sub New(ByVal name As String, ByVal id As Integer)
        Me.Name = name
        Me.Id = id
    End Sub
    Public Property Name() As String
        Get
            Return m_Name
        End Get
        Set(ByVal value As String)
            m_Name = Value
        End Set
    End Property
    Private m_Name As String
    Public Property Id() As Integer
        Get
            Return m_Id
        End Get
        Set(ByVal value As Integer)
            m_Id = Value
        End Set
    End Property
    Private m_Id As Integer
End Class


Private salutation As New List(Of SMSCLayer.Salutation)


    Public Sub FillSalutations()
        Dim Salutations As New List(Of String)
        Dim d As New SMSCLayer.Salutation
        Salutations = d.GetAll()
        For i As Integer = 0 To Salutations.Count - 1
            salutation.Add(New SMSCLayer.Salutation(Salutations(i).ToString(), i))
        Next

        cmbSalutation.DataSource = salutation
        cmbSalutation.DisplayMember = "Name"
        cmbSalutation.ValueMember = "Id"
        cmbSalutation.SelectedIndex = 0
        cmbSalutation.Focus()

    End Sub

No comments:

Using Authorization with Swagger in ASP.NET Core

 Create Solution like below LoginModel.cs using System.ComponentModel.DataAnnotations; namespace UsingAuthorizationWithSwagger.Models {     ...