Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7087495
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T07:40:52+00:00 2026-05-28T07:40:52+00:00

I seem to be having issues with the selected index on a list box.

  • 0

I seem to be having issues with the selected index on a list box.

The list box is having various items inserted depending on the user selection. An example would be:

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item1")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "AND")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item2")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "AND")

LiIndex = ListBox1.Items.Count      
ListBox1.Items.Insert(LiIndex, "Item3")

This all work and displays without a problem. The issue I have is if I select the second of the two AND’s. If I click the second “AND” in the list and then a button to fire a method, the selected index is always the index of the first “AND”.

Dim listIndex as integer = ListBox1.SelectedIndex

I can’t work out why, the listbox itself will always show the second one as selected, but the action will happen against the first one.

Any ideas as to where I am going wrong would be greatly appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T07:40:53+00:00Added an answer on May 28, 2026 at 7:40 am

    Wathever you want to achieve, handling the ListBox items directly is not a good place to start.
    You should use an ObservableList(Of String) as a property of your code and bind the list
    in xaml.
    After that your code becomes : MyItemList.Add(“My Item”)
    The issue might come from using SelectedItem in your code OR from the fact your’re displaying
    same object twice (i once had a strange behaviour in a CheckBox displaying twice same object)
    you can get rid of that by defining/using a class to store the data : anyway, it is not just
    about a string, no ? so you can have an ItemInfo class with a ToString Overload for it to display
    OR you define a DataTemplate in your Window resource that has ItemInfo as DataType.

    <DataTemplate DataType="{x:Type l:ItemInfo}">
            <TextBlock Text="{Binding ItemText}" />
    </DataTemplate>  
    

    and in your code you use, MyItemList beeing now an ObervableList(Of ItemInfo) : MyList.Add(New ItemInfo(” some text”, …) )
    so you never have twice same item.

    More work, but here we have more solid start to add data/functions after.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This would seem to be a simple .htaccess RewriteRule, yet I'm still having issues
I seem to be having a problem with checking for list equality. In my
I seem to be having two issues with my project after I converted from
I seem to be having some issues while attempting to implement logging into my
I'm having issues with this regex it doesn't seem to grab the titles (everything
I'm trying to port the speakhere example into another app and I'm having issues.
I seem to be having issues. I have a query string that has values
Im tryingh to create a list view but im having issues designing it how
I installed scala 2.8.0 last night and I seem to be having some issues
I seem to be having issues with using find() with the STL map on

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.