Third time...Listbox, Array and Selected Index

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • annie8508
    New Member
    • Apr 2012
    • 10

    Third time...Listbox, Array and Selected Index

    Hello..I'm almost done with this however and I posted it on Visual 3/4/6 and VBA and they directed me to this forum.. The selectedindex is not recognized in VB 2010 and ("co") is apparently should not be infinity?

    Please help I been working on this for a while


    Code:
    Public Class Form1
    
    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
    
    Dim strcountries() As String = {"United States", "France"} For intsubsript As Integer = 0 To 1 LstCountries.Items.Add(strcountries(intsubsript)) Next intsubsript
    
    End Sub
    
    Private Sub LstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCountries.SelectedIndexChanged
    
    Dim strcity() As String = {"Washington", "Paris"}
    
    Dim strIndex As String = LstCountries.SelectedIndex txtcity.Text = strcity(strIndex).ToString("co")
    
    End Sub End Class
    Last edited by Rabbit; Apr 9 '12, 04:21 PM. Reason: Please use code tags when posting code.
  • Monomachus
    Recognized Expert New Member
    • Apr 2008
    • 127

    #2
    Hi,
    Please post exactly the behavior you want to achieve, and also the error you are getting also I don't really understand what do you want to achieve with .ToString("co") ?
    Code:
    strcity(strIndex).ToString("co")

    Comment

    • annie8508
      New Member
      • Apr 2012
      • 10

      #3
      I trying to load Form1 with the name of the two countries in the LstCountries (a List Box) and the name of the capital of the country should show up in the txtcity.Text when I select the country in the list box..(match up to it)

      So when I click on US or France only Washington DC show up for both of them..

      Verse select US ..Washington Dc shows up
      Select France .....France should show up

      But selectedIndex is not recognizable by the Windows applications form for Visual Basic 2010 ..is there another way?
      I think this should be ok...if I get rid of the "co" I felt like something should go there...

      strcity(strInde x).ToString()

      Comment

      • annie8508
        New Member
        • Apr 2012
        • 10

        #4
        annie8508
        I trying to load Form1 with the name of the two countries in the LstCountries (a List Box) and the name of the capital of the country should show up in the txtcity.Text when I select the country in the list box..(match up to it)

        So when I click on US or France only Washington DC show up for both of them..

        Verse select US ..Washington Dc shows up
        Select France .....France should show up

        But selectedIndex is not recognizable by the Windows applications form for Visual Basic 2010 ..is there another way?
        I think this should be ok...if I get rid of the "co" I felt like something should go there...

        strcity(strInde x).ToString()

        Comment

        • Monomachus
          Recognized Expert New Member
          • Apr 2008
          • 127

          #5
          Code:
          Public Class Form1
          
              Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
          
                  Dim strcountries() As String = {"United States", "France"}
                  For intsubsript As Integer = 0 To 1
          
                      LstCountries.Items.Add(strcountries(intsubsript))
                  Next intsubsript
          
              End Sub
          
              Private Sub LstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCountries.SelectedIndexChanged
          
                  Dim strcity() As String = {"Washington", "Paris"}
          
                  Dim strIndex As Integer = LstCountries.SelectedIndex
                  txtcity.Text = strcity(strIndex).ToString()
          
              End Sub
          End Class
          The problem was that SelectedIndex is String in your code, but actually is an Integer

          Comment

          Working...