I have a List and a dataGridView1 and I’m trying to do this:
var result = from s in sessions
where s.ID > 0
select s;
dataGridView1.DataSource = result;
It compiles fine, nothing shows in the DataGridView and no exceptions.
If I however set dataGridView1.DataSource = sessions; it shows everything.
Do:
In fact because of linq deferred execution, your linq query doesn’t execute until you fetch some data.
If you add ToList and you see nothing, it means that there is no result and nothing goes wrong, just check your
result.ToList()in watch window in debug mode, if there isn’t any result it’s OK, but if you see some result may be you should refresh your dataGridView or rebind it.