Sort Datagridview columns when datasource binded to List(Of T)
Asked Answered
I

1

1

I have a datagridview with its datasource binded to a List(Of T). Now i would like to sort on any of the columns.

My code:

'Database access : items = List(BlogPost)
dgBlogPosts.DataSource = items

'My BlogPost Class
Public Class BlogPost

    Public Property ID As Integer
    Public Property Title As String
    Public Property Content As String
    Public Property CreationDate As DateTime
    Public Property Rating As Decimal = 5.0

End Class
Irrigation answered 4/2, 2011 at 15:47 Comment(2)
datagridview or gridview or datagrid?Merth
datagridview as described in the topic.Irrigation
D
2

Take a look at this example which recommends using a BindingList instead and then a bit of code to enable sorting. There is also this on codeproject.

Devault answered 5/2, 2011 at 13:23 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.