Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
155
Valuelist from Generic List of Valuelistitems
posted

Hi,

What do I ned to do to get a Valuelist Out of a List of (for Example Integer and String)?

If I create a Generic List of Valuelistitems like:

Dim mListOfItems = (from Items in mIntStringlist Select New Valulistitem with {.DataValue = Items.Value, .Displaytext = Items.DText}).tolist

I don't know how to get it into a Valuelist beside iterating for each item...

Is there a better way using linq?

 

 

Parents
  • 469350
    Verified Answer
    Offline posted

    Hi,

    The ValueListItems collection has an AddRange method which takes in an Array of ValueListItems. So if your only concern is writing the least possible amount of code, you could call ToArray on your list and pass that into AddRange.

    This is not very efficient, though, since you are creating a list, copying it to an array, and then the ValueList will end up iterating the array, anyway.

    What I would do is - don't return ValueListItems from the LINQ query. Instead, return some other object custom object with two properties for the DataMember and DisplayMember. Then you can create a List<T> of those object and use data binding to populate a BindableValueList.

    But it really doesn't matter much  - either way will work. :)

Reply Children
No Data