Frosty214 Frosty214 - 1 year ago 125 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!

Answer Source

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
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download