So I have a query with results that I want to put into a datagridview. I have it working except I get an error on the last line.
The error i get is DataGridView control must be bound to an IBindingList object to be sorted.
I am not sure what to do. Maybe the tolist isnt the right way to go. Can I create a datatable from the results? I have searched and saw the copytodatatable, but that doesnt work because of the of anonymous type. Please help.
VB.NET:
Private Sub frm_loadcards_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load
Me.ModetypeTableAdapter.Fill(Me.FlightTestApp2DataSet.modetype)
Me.FlightcardTableAdapter.Fill(Me.FlightTestApp2DataSet.flightcard)
Dim cards = FlightTestApp2DataSet.Tables("flightcard")
Dim mode = FlightTestApp2DataSet.Tables("modetype")
Dim query = From c In cards.AsEnumerable Join m In mode.AsEnumerable
On c.Field(Of Integer)("mode_id") Equals m.Field(Of Integer)("mode_id")
Select New With
{
.flightcardid = c.Field(Of Integer)("flightcard_id"),
.flightcardname = c.Field(Of String)("name"),
.flightcardrev = c.Field(Of Integer)("revision"),
.flightcardmode = m.Field(Of String)("abbreviation")
}
Dim results = query.ToList
Me.DataGridView1.DataSource = results
Me.DataGridView1.Columns(0).Visible = False
Me.DataGridView1.Columns(1).HeaderText = "Name"
Me.DataGridView1.Columns(2).HeaderText = "Rev"
Me.DataGridView1.Columns(3).HeaderText = "Mode"
Me.DataGridView1.Sort(Me.DataGridView1.Columns(3), System.ComponentModel.ListSortDirection.Ascending)
End Sub
The error i get is DataGridView control must be bound to an IBindingList object to be sorted.
I am not sure what to do. Maybe the tolist isnt the right way to go. Can I create a datatable from the results? I have searched and saw the copytodatatable, but that doesnt work because of the of anonymous type. Please help.
Last edited: