VB.NET School Assignment? Project Due Tomorrow? Chat LIVE With A Programming Expert!

Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 300,466 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 1,706 people online right now. Registration is fast and FREE... Join Now!




Problem with Combo Box Selected Index Changed Event

 

Problem with Combo Box Selected Index Changed Event

antitru5t

1 Jul, 2009 - 09:56 AM
Post #1

New D.I.C Head
*

Joined: 19 Jan, 2009
Posts: 27


My Contributions
Here is my code for programming a program that reads from a file called RESORT.TXT

Containing the text:
Barb Allen
604 777 1234
2008/12/01
2
3
1
3
D
Eric Meyer
604 527 9123
2008/12/18
4
3
2
1
B
Victor Choong
604 525 3123
2008/11/18
2
2
1
2
N
Gilbert Tsui
604 521 1123
2008/12/28
5
1
0
4
D
Eric Meyer
604 527 3123
2009/01/08
1
2
1
3
D

Here is my source code::

CODE

Public Class frmResort

    Structure resortStructure
        Dim customerName As String
        Dim phoneNumber As String
        Dim checkInDate As Date
        Dim daysToStay As Integer
        Dim numberOfAdults As Integer
        Dim numberOfKids As Integer
        Dim mealPlan As Char
        Dim memberLetter As String
    End Structure

    Dim guestlist(4) As resortStructure

    Private Sub frmResort_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
        Dim sr As IO.StreamReader = IO.File.OpenText("RESORT.TXT")
        For i As Integer = 0 To 4
            guestlist(i).customerName = sr.ReadLine
            guestlist(i).phoneNumber = sr.ReadLine
            guestlist(i).checkInDate = CDate(sr.ReadLine)
            guestlist(i).daysToStay = CInt(sr.ReadLine)
            guestlist(i).numberOfAdults = CInt(sr.ReadLine)
            guestlist(i).numberOfKids = CInt(sr.ReadLine)
            guestlist(i).mealPlan = CChar(sr.ReadLine)
            guestlist(i).memberLetter = sr.ReadLine
        Next
        sr.Close()
        For i As Integer = 0 To 4
            cmbGuestSearch.Items.Add(guestlist(i).customerName & "  " & guestlist(i).phoneNumber)
        Next

    End Sub

    Sub ProcessData()
        lstInvoice.Items.Clear()
    End Sub

    Sub ProcessInvoice()
        Dim fmtStr As String = "{0, -4} {1, 10}"
        For i As Integer = 0 To 4
            lstInvoice.Items.Add(guestlist(i).customerName)
            lstInvoice.Items.Add(guestlist(i).phoneNumber)
            lstInvoice.Items.Add(guestlist(i).checkInDate)
            lstInvoice.Items.Add(guestlist(i).daysToStay)
            lstInvoice.Items.Add(guestlist(i).numberOfAdults)
            lstInvoice.Items.Add(guestlist(i).numberOfKids)
            lstInvoice.Items.Add(guestlist(i).mealPlan)
            lstInvoice.Items.Add(guestlist(i).memberLetter)
        Next
    End Sub

    Private Sub btnPrepareInvoice_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnPrepareInvoice.Click
        ProcessData()
        ProcessInvoice()
    End Sub

    Private Sub cmbGuestSearch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbGuestSearch.SelectedIndexChanged
        For i As Integer = 0 To 4
            txtGuestName.Text = guestlist(i).customerName
        Next
    End Sub
End Class


I have also included a screenshot of the program.

IPB Image

I have a problem when I use the SelectedIndexChanged to get the index using: txtGuestName.Text = guestlist(i).customerName using the for loop.

I am so puzzled because everytime I change the index, it shows the same thing. For example, when I click Victor Choong, it still displays Eric Meyers.

Can anyone help here? Thanks.

- Nathe

This post has been edited by antitru5t: 1 Jul, 2009 - 09:58 AM

User is offlineProfile CardPM
+Quote Post


bflosabre91

RE: Problem With Combo Box Selected Index Changed Event

1 Jul, 2009 - 10:11 AM
Post #2

go sabres
****

Joined: 22 Feb, 2008
Posts: 658



Thanked: 12 times
My Contributions
CODE

Private Sub cmbGuestSearch_SelectedIndexChanged(ByVal sender As Object, ByVal e As System.EventArgs) Handles cmbGuestSearch.SelectedIndexChanged
        For i As Integer = 0 To 4
            txtGuestName.Text = guestlist(i).customerName
        Next
    End Sub



that looks like its your problem. what are you trying to do on selectedindexchanged? all this is going to loop 5 times and change the txtGuestName text each time, Eric Meyer is just the person in the guestlist with an index of 4. How are you filling the combobox? Check out the ValueMember and the DisplayMember properties of the Combobox. This will allow you specify what is shown when a row is selected, and what the value will be. then you can use that to find the Guest Name. Seems kinda redundant to have the guest name in there twice though....
User is offlineProfile CardPM
+Quote Post

antitru5t

RE: Problem With Combo Box Selected Index Changed Event

1 Jul, 2009 - 10:17 AM
Post #3

New D.I.C Head
*

Joined: 19 Jan, 2009
Posts: 27


My Contributions
I want my SelectedIndexChanged to follow through. When I change an index in my combobox, cmbGuestSearch, it should bring me the right index and the right name of the person.

I can't seem to do that. sad.gif
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic

Time is now: 11/8/09 02:34AM

Live VB.NET Help!

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter Fan Us On Facebook

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month