Solved

# How to modify a value inside a 1 dimension listBox

Posted on 2011-04-20
335 Views
Hello EE,

Lets say I have a Listbox that has been filled with a 1 dimensional array such as

1, 0
100,1
455,2
900,3
etc

how do I modify a single value inside it?

in other words see my code... I know its not good but lets say oldValue = 455  want to modify it so it will be replace by  -1

any ideas?
For x As Integer = 0 To ListBox4.Items.Count - 1
Dim myMatch As New MatchData
myMatch = ListBox4.Items(x)
If myMatch.Value = oldValue Then
ListBox4.Items(x)(0) = "Done"
End If
Next
0
Question by:PhilippeRenaud

LVL 1

Author Comment

sorry its not "done" in the code  but   -1
0

LVL 83

Assisted Solution

Try

Listbox1.Items(Listbox1.FindStringExact(oldvalue)) = newvalue
0

LVL 1

Author Comment

I understand what your line does, but, the problem is that if I have multiple same values.. it would find 2 rows

does it have like a FindStringExactAt   lol?   for index or something?

do you know what I mean
0

LVL 83

Expert Comment

Your loop will do the same as well!
0

LVL 1

Author Comment

lol right. sorry ;)
0

LVL 1

Author Comment

mmm..  is it possible that it replace all the item at  my index by new value ?  Like if it was becoming a non dimensional line ?

becasue I am having an error saying unable to cast int32 type to  [.....] MatchData

MatchData is a combinaison of 2 values    (value and index)

i woudl like to keep the index but just modify the value.. not sure if Im doing this correctly with your last comment

or am i wrong ?
0

LVL 83

Expert Comment

My approach would not work with items of a custom type. Looping would work though.
0

LVL 85

Accepted Solution

Something like:
For md As MatchData in ListBox4.Items
If md.Value = oldValue Then
md.Value = -1
End If
Next

0

LVL 1

Author Closing Comment

thanks
0

LVL 1

Author Comment

hey guys :)

if you didnt see it, I have another question here :

http://www.experts-exchange.com/Programming/Languages/.NET/Visual_Basic.NET/Q_26968746.html
0

## Featured Post

### Suggested Solutions

Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Exception Handling is in the core of any application that is able to dignify its name. In this article, I'll guide you through the process of writing a DRY (Don't Repeat Yourself) Exception Handling mechanism, using Aspect Oriented Programming.
Sending a Secure fax is easy with eFax Corporate (http://www.enterprise.efax.com). First, Just open a new email message.  In the To field, type your recipient's fax number @efaxsend.com. You can even send a secure international fax — just include t…
In this seventh video of the Xpdf series, we discuss and demonstrate the PDFfonts utility, which lists all the fonts used in a PDF file. It does this via a command line interface, making it suitable for use in programs, scripts, batch files — any pl…