NameValueList question
Old forum URL: forums.lhotka.net/forums/t/1369.aspx
Pradeep posted on Monday, October 02, 2006
I have the following lookup items
Key Value
---- ------
10 Open
20 InProcess
30 Completed
40 Terminated
I loaded this into NameValueList. But when I try to query the list by index, example MyList[20], it is not searching by the key. I am getting index out of range exception.I think that makes sense.
So what I am doing is, inside my property's get method, I am using a for loop to loop through all the key's and see which key matches. Then get the index of that and find the value.
Just wondering if there is any other easy way (one line code), to do this. Also I am worried that looping through a list of 100 values everytime might be a performance issue.
Please let me know how you guy's do this. Is there more elegant way?
Thank You
malloc1024 replied on Monday, October 02, 2006
MyList[20] retrieves
the 20 item in the list. You get an error because you only have 4 in
your list. Yes, looping through the list
is the appropriate way to handle this situation. An alterative is to use a hash table if you
don’t want to loop.
Brian Criswell replied on Monday, October 02, 2006
This is all the .NET framework does for its Find methods, so I would not worry about searching 100 items. If all you are doing is checking a single property each time through the list, you will blink and miss it finishing. I think you are going in a good direction with this. Make it work, then optimize it if you actually need to do so.
xal replied on Monday, October 02, 2006
NameValueLists have a "Value()" method that take the id as a parameter.
Like: myNvl.Value(someId).
Andrés
Pradeep replied on Monday, October 02, 2006
Thank You guy's.
Xal,
I don't see a value property. I see valuelist property. But again, I am using 1.5 version. May be the value property is in 2.0 version.
Pradeep
Copyright (c) Marimer LLC