Results 1 to 3 of 3

Thread: List box data showing info in Label

  1. #1

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    8

    List box data showing info in Label

    I am working on the following problem: Have list box and label. In the list box when I highlight an item it should show in the label the assigned value. I am lloking to do it with Select Case statement.
    This is what I have up to this moment:

    Public Class PhoneForm
    Inherits System.Windows.Forms.Form
    Dim mstrIndex As String

    Private Sub ExitButton_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles ExitButton.Click
    Me.Close()
    End Sub


    Private Sub PhoneForm_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles MyBase.Load
    Dim strName() As String = {"Smith, Joe", "Jones, Mary", "Adkari, Joel", "Lin, Sue", "Li, Vicky"}
    Dim intX As Integer
    For intX = 0 To 4
    Me.NameListBox.Items.Add(strName(intX))
    Next intX
    Me.NameListBox.SelectedIndex = 0
    End Sub

    Private Sub NameListBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameListBox.TextChanged
    Me.ExtensionLabel.Text = "choose the name"
    mstrIndex = Me.NameListBox.SelectedItem
    Select Case mstrIndex
    Case Is = "Smith, Joe"
    Me.ExtensionLabel.Text = "3388"
    Case Is = "Jones, Mary"
    Me.ExtensionLabel.Text = "3356"
    End Select
    End Sub
    End Class

    I have a question:
    WHY I AM NOT GETING VALEPrivate Sub NameListBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameListBox.TextChanged
    Me.ExtensionLabel.Text = "choose the name"
    mstrIndex = Me.NameListBox.SelectedItem
    Select Case mstrIndex
    Case Is = "Smith, Joe"
    Me.ExtensionLabel.Text = "3388"
    Case Is = "Jones, Mary"
    Me.ExtensionLabel.Text = "3356"
    End Select
    End Sub
    End ClassPrivate Sub NameListBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameListBox.TextChanged
    Me.ExtensionLabel.Text = "choose the name"
    mstrIndex = Me.NameListBox.SelectedItem
    Select Case mstrIndex
    Case Is = "Smith, Joe"
    Me.ExtensionLabel.Text = "3388"
    Case Is = "Jones, Mary"
    Me.ExtensionLabel.Text = "3356"
    End Select
    End Sub
    End Class

    I have a question:

    WHY I AM NOT GETTING VALUES SHOWN IN THE LABEL TEXT BOX?
    WHAT AM I MISSING?

    Thanks

  2. #2
    Super Moderator Wokawidget's Avatar
    Join Date
    Nov 2001
    Location
    Headingly Occupation: Classified
    Posts
    9,632
    OK. 1stly, this is .NET, not VB6. You have posted in the wrong forum.
    2ndly, when posting code use the [VBCODE ] and [/VBCODE ] tags, without the spaces. This makes it way easier for us to read your posts.
    Try:
    VB Code:
    1. Private Sub NameListBox_TextChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles NameListBox.TextChanged
    2.    Me.ExtensionLabel.Text = "choose the name"
    3.    mstrIndex = Me.NameListBox.SelectedItem
    4.    Select Case mstrIndex
    5.       Case Is = "Smith, Joe"
    6.          Me.ExtensionLabel.Text = "3388"
    7.       Case Is = "Jones, Mary"
    8.          Me.ExtensionLabel.Text = "3356"
    9.       Case Else
    10.          Me.ExtensionLabel.Text = mstrIndex & " not found"
    11.    End Select
    12. End Sub
    Does your label always have the "not found" caption?

    Woka

  3. #3

    Thread Starter
    New Member
    Join Date
    Sep 2003
    Posts
    8

    THANKS

    THanks to everybody who replied. I fixed the problem...
    I am working in VB.NET not in VB6.

    SPASIBO!

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width