what is the most robust method for adding a empty row (to select “nothing”) to a ListBox?
Sofar i used:
Dim List = Enumerable.Repeat(New TABLE With {.Text = "", .ID = -1}, 1).AsQueryable().Union(From t In mainctx.TABLEs)
ddlMangelKategorie.DisplayMember = "Text"
ddlMangelKategorie.ValueMember = "ID"
ddlMangelKategorie.DataSource = List.ToList
But this has some drawbacks:
- wordy
- must explicit write the Type (TABLE in this case), so i cant wrap this in a function
- have not found an solution, which works with anonymous types
I.e. if I add a
From t In mainctx.TABLEs Select Text=col1, id=col2
to the query, this method does not work anymore.
Thanks
Here’s how I would do it using
Union(notice that you don’t needEnumerable.RepeatnorAsQueryable).With anonymous types: