Bindingsource按列值,datagridview排序

时间:2012-03-21 17:48:39

标签: vb.net datagridview bindingsource

我正在尝试在datagridview中显示一个足球联赛表。我的代码从ms访问中获取每列的数据,并将其显示在datagridview中。我想根据“pts”列的值对行进行排序。我尝试使用BindingSource.Sort =“pts”,但这没有任何效果。 继承了我的一些代码,任何帮助都会受到赞赏!

Private Sub Form1_Load(ByVal sender As System.Object,ByVal e As System.EventArgs)处理MyBase.Load         OleDbConnection1.Open()         Dim命令As OleDbCommand = New OleDbCommand()         command.Connection = OleDbConnection1         command.CommandType = CommandType.StoredProcedure         command.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

1 个答案:

答案 0 :(得分:0)

据我所知,这是对象数据源,您需要在其中实现自己的排序。

看看这是否有帮助:绑定列表中的Sorting Objects