简体   繁体   English

绑定源按列值排序,datagridview

[英]Bindingsource sort by column value, datagridview

I am trying to display a football league table in datagridview. 我试图在datagridview中显示一个足球联赛表。 my code gets that data for each column from ms access and displays it in datagridview. 我的代码从ms访问中获取每一列的数据,并将其显示在datagridview中。 I want to sort rows according to the value of the "pts" column.I've tried using using BindingSource.Sort = "pts" but this has had no effect. 我想根据“ pts”列的值对行进行排序。我尝试使用BindingSource.Sort =“ pts”,但这没有任何效果。 heres my some of my code any help would be appreciated! 这是我的一些代码,任何帮助将不胜感激!

Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load OleDbConnection1.Open() Dim command As OleDbCommand = New OleDbCommand() command.Connection = OleDbConnection1 command.CommandType = CommandType.StoredProcedure command.CommandText = "Query7" 私有子Form1_Load(ByVal发送者作为System.Object,ByVal e作为System.EventArgs)处理MyBase.Load OleDbConnection1.Open()Dim命令作为OleDbCommand = New OleDbCommand()command.Connection = OleDbConnection1 command.CommandType = CommandType.StoredProcedure命令。 CommandText =“ Query7”

    Dim objReader As OleDbDataReader = command.ExecuteReader

    TeamBindingSource.Clear()


    Do While objReader.Read()

        Dim tm = objReader("teamname")

        Dim mp, w, d, l, f, a, p As Integer

        mp = Getgamesplayed(OleDbConnection1, tm)
        w = GetGamesWon(OleDbConnection1, tm)
        d = GetGamesdrawn(OleDbConnection1, tm)
        l = 0
        f = GetGoalsScored(OleDbConnection1, tm)
        a = GetGoalsConceeded(OleDbConnection1, tm)
        p = 0
        Dim team As New Team(tm, mp, w, d, l, f, a, p)
        TeamBindingSource.Sort = "pts"
        TeamBindingSource.Add(team)

    Loop
End Sub

From what I understand, this is Object Data Source where you need to implement your own sorting. 据我了解,这是对象数据源,您需要在其中实现自己的排序。

See if this helps: Sorting Objects in Binding list 看看是否有帮助:在绑定列表中对对象进行排序

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM