By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
455,684 Members | 1,309 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 455,684 IT Pros & Developers. It's quick & easy.

Listbox1 problem

P: n/a
Jan
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.SelectedItem

item = textline.Split(";")
item(3) = " " & NumericUpDown1.Value
textline = Join(item, ";")

lstWoodshop.Items.Insert(lstWoodshop.SelectedIndex , 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
Nov 20 '05 #1
Share this Question
Share on Google+
2 Replies


P: n/a
"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.SelectedItem
I see, you are not using Option Strict, do you? :-)
item = textline.Split(";")
item(3) = " " & NumericUpDown1.Value
textline = Join(item, ";")

lstWoodshop.Items.Insert(lstWoodshop.SelectedIndex ,
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

Nov 20 '05 #2

P: n/a
Hi,

listbox1.items.removeat.

dim textline as string
dim item(3) as string

textline = lstWoodshop.SelectedItem

item = textline.Split(";")
item(3) = " " & NumericUpDown1.Value
textline = Join(item, ";")
lstWoodshop.Items.RemoveAt(lstWoodshop.SelectedInd ex) lstWoodshop.Items.Insert(lstWoodshop.SelectedIndex , textline)
Ken
--------------------------
"Jan" <ca*****@planet.nl> wrote in message
news:x2******************************@40tude.net.. . 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.SelectedItem

item = textline.Split(";")
item(3) = " " & NumericUpDown1.Value
textline = Join(item, ";")

lstWoodshop.Items.Insert(lstWoodshop.SelectedIndex , 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

Nov 20 '05 #3

This discussion thread is closed

Replies have been disabled for this discussion.