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?
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. :)
Thank you, this is what I suspected. I stumbled over this, as another developer was using my functions (which return two values) pointing to his function which adds 1 empty Value List item (DBNull.Value) and then iterates through my list and adding each item to a ValueList which is then the Return of his Function.
These Value Lists are then assigned to several different Columns as Value Lists, replacing Numbers with some Text.
I guess he did this because he wanted to assigne only one type of List, as I have got 3 different Functions, one Returning a list of Integer, String, one for String, String and one for String, Integer.
Therefore I asked if there would be a more simple way to fill a ValueList directly using Linq.