Frosty214 Frosty214 - 1 month ago 9 Question

Visual Basic: How To Create a LINQ Statement for DataGridView Control?

I'm having an issue with creating a LINQ statement for a DGV control.

What it's supposed to do:

When I click on a country listed from a combobox I've placed on my Form, it is supposed to act as a filter.

Example: When Brazil is selected, the DGV will then display the CustomerID, Region, etc connected to Brazil.

The issue is, I'm definitely aware that this isn't correct. When I do click on a country from the combobox, the DGV will only display blank spaces, or "length."


Dim Q = From Query in DSname.Customers
Where Query.Country = ComboBox.Text
Select Query.CustomerID

DataGridView.DataSource = Q.ToList()

Any help will be appreciated, thank you!


This should pull each record that matches the criteria. Don't add the Select part at the end.

Dim query = (From cust in DSname.Customers
             Where cust.Country = ComboBox.Text).ToList

DataGridView.DataSource = query