Selecting an item from the list

I read on a specific site that the code is:

 txtBox = lstBox.ItemData(lstBox.ListIndex())

      

will give me an item to click in the list, where ListIndex provides me with a string and ItemData provides me with data in a string. However, while trying to implement it, I noticed that no such option exists for my list. Is there something that needs to be added to the code to use such parameters? I am programming using C # language

0


a source to share


2 answers


I think you have vb6 code you are trying to implement in .net language ... from .net help:

In Visual Basic 6.0, the ItemData property for a ComboBox control can be set at design time in the properties to associate an integer with a ComboBox item.

In Visual Basic 2008, the ItemData property no longer exists. The Microsoft.VisualBasic.Compatibility library contains the SetItemData function that can be used to associate an integer with an item; The GetItemData function can be used to retrieve an item.



Best wishes don

+1


a source


Use ListBox.SelectedItem . Note that this returns an object, so you will need to discard anything that will revert to the type you want. For instance:



var selectedItem = (int)myListBox.SelectedItem;

      

0


a source







All Articles