Yes you are right, that was kind of obvious i guess. However i mostly tried that statement because i could not get anything else to work.
I just found the solution now. I had to set the
AppendDataBoundItemsproperty of the ListBox to True, aswell as removing the statement you pointed out.
Thanks for looking through my questions once again.
Edit: Here is another attempt in case someone is interested.
Code:
Using myEnt As New PicturesEntities()
Dim picCount = From tag In myEnt.Pictures
Order By tag.Id Descending
Select tag.Id
For Each li As ListItem In TagLB.Items
If li.Selected Then
Dim tg As New TagLink
Dim tx As ListItem = li ' (compiler complained when i used the iterator)
Dim tagsX = From tag In myEnt.Tags
Order By tag.Id
Where tag.TagName = tx.Text
Select tag.Id
tg.TagId = tagsX.First
tg.PictureId = picCount.FirstOrDefault + 1
myEnt.TagLinks.AddObject(tg)
myEnt.SaveChanges()
End If
Next
End Using