[RESOLVED]listbox tag and index property
is it possible to set the tag and index property in a listbox?
if not, how do i read all listbox members one at a time and get their tag property that was set...
sorry if it seems stupid, but 2 hours of searching the net and 6 books later i still don't have an answer.
i'm beginning to like cobol again.
Re: listbox tag and index property
hmm dont have VB so just typing
For i as integer = 0 to myListBox.Items.Count -1
myListBox.Items(i).Tag = '...
Next
Re: listbox tag and index property
Nah, the listbox only has the Tag() property on the control, not on the individual items. To do the equivalent, simply include the ToString() function in your class and in that function, have it return the value you wish to have displayed.
Then simply add it to the ListBox. The control will then accept the class (because it accepts any object derived from Object) and then uses the ToString() method to determine what to display. When you use properties like SelectedItem(), it will return your class that you put in, simply convert it using the CType() function and you can use it.
Re: listbox tag and index property
so what your telling me is i can't store the tag (what i need) from a listbox list of items?
what happens is a user chooses something from a list view, the tag and data get written to the list box, as a visual que of what will be written to the db...i want to roll through the box when the user clicks the apply button and write the tags to the table, otherwise i am duplicating data a major no no.
i can message box out the tag (ie it shows the correct tag for each item) in the selecteditemschanged event so i know the tag is following the item over.
i tried using two listviews but couldn't get the second one to display the items.
Re: listbox tag and index property
Can you rephrase that, I didn't quite understand that sorry.
Re: listbox tag and index property
Hi,
It's slightly mysterious, given that a lot of the properties of objects have been aligned in the transition from VB6 to .Net, but the ListViewItem class uses the .Tag property to store stuff whereas the ListItem uses the .Value property.
You just refer to each of these as said so politely by Mr Polite, although in the form above.
Is that of help?
zaza
Re: [RESOLVED]listbox tag and index property
I resolved the dual listview issue, i hadn't created a column to put the data into so it wasn't showing up...
all fixed...now for the numeric up down,.