1 year ago
#386622
seeker
How to use LINQ to Fill List<string> with column values
I'm looking for a solution to fill a ComboBox with column values of a LINQ statement.
List<string> comboList = new List<string>();
I have a table with localisation data.
This table looks like
ID;Language;Argument1;Argument2;Argument3;Argument4; and so on
I want the value of Argument1;Argument2;Argument3;Argumant4; and so on
.
My simple LINQ expression is:
var query = (from x in dc.tblListItems
where x.Language == "English"
select x).FirstOrDefault();
There will be more columns in the future, so I can't select it in the LINQ query directly.
Now I try to fill the List<string>
for myComboBox with the column values except the first two ones ID;Language
foreach (var item in query)
{
System.Reflection.PropertyInfo[] fields = query.GetType().GetProperties();
foreach (var f in fields)
{
comboList.Add(f.GetValue(item).ToString());
}
}
But this attempt fail.
I hope you have a solution for me.
list
linq
combobox
0 Answers
Your Answer