"Jan" <ca*****@planet .nl> schrieb
Hi there,
I'm a newbee in vb.net with the following problem:
4444528; Baltic Birch; 16.20; 0
I have more of these lines in a ListBox1.
Now I want to change the latest 0 with the value of a NumericUpDown1
(for ex. 8)
My solution is this:
dim textline as string
dim item(3) as string
textline = lstWoodshop.Sel ectedItem
I see, you are not using Option Strict, do you? :-)
item = textline.Split( ";")
item(3) = " " & NumericUpDown1. Value
textline = Join(item, ";")
lstWoodshop.Ite ms.Insert(lstWo odshop.Selected Index,
textline)
so far so good, but the old line with the 0 at the end still stays in
the ListBox1. How can I remove this? I tried many options, but i
always get a error?
Somebody knows they answer?
Thank you very much
Usually it is better to keep the data in variables, change them, and reflect
the changes in the UI, i.e. in the listbox. There are different approaches.
One is:
1. Write a class containing the data (4444528, "Baltic Birch", etc.).
2. "Override" the ToString function that returns a string to be displayed in
the listbox.
3. Create instances of the class and add them to the listbox. The listbox
calls the ToString method of every object added to get the string to be
shown.
Unfortunately I didn't find a way to make the listbox look for the current
values and display them whenever you change them. So, you can get the item
from the listbox, change the value, remove the item (Items.Remove) and add
it again (Items.Insert). If there is a small number of list items and/or
they change rarely, an alternative is to clear the listbox and fill it again
(to avoid writing a "change item procedure").
--
Armin