I am filling data from removeActiveService
(list of listItem) into a new list listRemove
. However listRemove
is turning into a list of Long.
Dim listRemove = removeActiveService.Select(Function(item) item.Text.Replace(serviceRemove, "") And item.Text.Split("-"c)(0).Trim And item.Value.Split("-"c)(1).Trim).ToList()
If I change it to Dim listRemove As List(Of ListItem)
, it results in the error
Value of type List(Of Long) cannot be converted to List(Of ListItem)
I need to perform replace and split on the text and value (see my code). What is the correct syntax here so that it can be a List(Of ListItem)?
EDIT
Starting with checkboxlist items in
removeActiveService
Copy that into a brand new list of items called
listRemove
.I need to perform these on the TEXT of the list items in
listRemove
- item.Text.Replace(serviceRemove, "")
- item.Text.Split("-"c)(0).Trim
- And I need to perform this on the VALUE of the list items in
listRemove
- item.Value.Split("-"c)(1).Trim
CodePudding user response:
If you expect to output a List(Of ListItem)
then you need to create ListItem
objects somewhere, which you're not doing now. You're performing operations on the input data but you're not doing anything useful with the results. And
doesn't do anything that could be considered useful there. If you expect to output a list of ListItem
objects containing the results of those operations then you actually have to create ListItem
objects containing the result of those operations. As far as I can tell, this would be the way to go:
Dim listRemove = removeActiveService.Select(Function(item) New ListItem With
{
.Text = item.Text.Replace(serviceRemove, "").Split("-"c)(0).Trim(),
.Value = item.Value.Split("-"c)(1).Trim()
}).
ToList()