473,326 Members | 2,126 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 software developers and data experts.

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


Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3. Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5. Dim strcountries() As String = {"United States", "France"} For intsubsript As Integer = 0 To 1 LstCountries.Items.Add(strcountries(intsubsript)) Next intsubsript
  6.  
  7. End Sub
  8.  
  9. Private Sub LstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCountries.SelectedIndexChanged
  10.  
  11. Dim strcity() As String = {"Washington", "Paris"}
  12.  
  13. Dim strIndex As String = LstCountries.SelectedIndex txtcity.Text = strcity(strIndex).ToString("co")
  14.  
  15. End Sub End Class
Apr 9 '12 #1

✓ answered by Monomachus

Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5.         Dim strcountries() As String = {"United States", "France"}
  6.         For intsubsript As Integer = 0 To 1
  7.  
  8.             LstCountries.Items.Add(strcountries(intsubsript))
  9.         Next intsubsript
  10.  
  11.     End Sub
  12.  
  13.     Private Sub LstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCountries.SelectedIndexChanged
  14.  
  15.         Dim strcity() As String = {"Washington", "Paris"}
  16.  
  17.         Dim strIndex As Integer = LstCountries.SelectedIndex
  18.         txtcity.Text = strcity(strIndex).ToString()
  19.  
  20.     End Sub
  21. End Class
The problem was that SelectedIndex is String in your code, but actually is an Integer

4 2324
Monomachus
127 Expert 100+
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") ?
Expand|Select|Wrap|Line Numbers
  1. strcity(strIndex).ToString("co")
  2.  
Apr 9 '12 #2
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(strIndex).ToString()
Apr 9 '12 #3
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(strIndex).ToString()
Apr 9 '12 #4
Monomachus
127 Expert 100+
Expand|Select|Wrap|Line Numbers
  1. Public Class Form1
  2.  
  3.     Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
  4.  
  5.         Dim strcountries() As String = {"United States", "France"}
  6.         For intsubsript As Integer = 0 To 1
  7.  
  8.             LstCountries.Items.Add(strcountries(intsubsript))
  9.         Next intsubsript
  10.  
  11.     End Sub
  12.  
  13.     Private Sub LstCountries_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstCountries.SelectedIndexChanged
  14.  
  15.         Dim strcity() As String = {"Washington", "Paris"}
  16.  
  17.         Dim strIndex As Integer = LstCountries.SelectedIndex
  18.         txtcity.Text = strcity(strIndex).ToString()
  19.  
  20.     End Sub
  21. End Class
The problem was that SelectedIndex is String in your code, but actually is an Integer
Apr 9 '12 #5

Sign in to post your reply or Sign up for a free account.

Similar topics

3
by: Chris Thunell | last post by:
I have a Listbox on an vb aspx web page. When i select something in the listbox i do not get a selected value or selected index. The selected index is always -1. Any thoughts would be greatly...
4
by: wolfgang wagner | last post by:
hi all! after successfully integrating a dropdownlist in my datagrid i have another problem: i cannot set the selected index of the dropdownlistbox. here is my code: hardware.aspx...
4
by: Paul | last post by:
Hi I have a page that pops up a warning box if a selection is not made, see below. <script language="javascript" event="onclick" for="btn_submit"> if(document.Form1.drp_dn_arriv.selectedIndex==0)...
11
by: Santosh | last post by:
Dear all , i am writting following code. if(Page.IsPostBack==false) { try { BindSectionDropDownlist();
1
by: RichGK | last post by:
The first time I run my code the list box sends a selected index changed event even though at this point there has been no activity with the mouse. The value returned from SelectedValue according...
0
by: hennas | last post by:
Basically i want to design a membership Name and Telephone List form using the following command buttons. Edit Add New; Update; Delete; Cancel; Save; Clear, and Exit
2
by: abhii | last post by:
HELLO EVERYONE, can u plz tell me that how can i get the previousely selected index in the listbox....
3
by: Sweetiecakes | last post by:
Hi I have an string array containing file paths. I have added them to a ListBox with AddRange(); When I delete an item from the ListBox, how can I delete the same item from the original...
1
by: kapil tripathi | last post by:
1) Accpet the item in TxtItem in comma seperated values like (Apple, Mango, Orange etc.). Store that item in array object (objArray) in acending order." 2) Create the object of the dropdown...
2
JnrJnr
by: JnrJnr | last post by:
I'm going to leave out most details so say for instance i have a combobox and when I select a car from the combobox I have a variable called Index that grows with each selection of the combobox. that...
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.