本文介绍了datagrid行计数器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个数据网格,看起来像:



i have a datagrid which looks like:

subject        students
eg1001         182737H
               29837B
               29837C
               19282W
eg1002         192837C
               32810H



等等。



我怎么能做一个计数器并放入主题和学生之间的专栏?喜欢:




so on and so forth.

how can i do a counter and put into a column between subject and students? like:

subject         numberofstudent   students
eg1001             4              182737H
                                  29837B
                                  29837C
                                  192823W
eg1002              2             192837C
                                  32810H



我的代码如下:




my codes are as follows:

Dim connect As String
       connect = "Provider=Microsoft.ACE.OLEDB.12.0; Data Source=" & Application.StartupPath & "\segdata.accdb"
       Dim conn As New OleDbConnection(connect)
       Dim cmd As OleDbCommand = New OleDbCommand
       cmd.Connection = conn
       conn.Open()
       cmd.CommandText = "SELECT DISTINCT ModuleCode, AdminNo FROM(SEGDATA)ORDER BY ModuleCode ASC, AdminNo ASC"
       Dim dt As New DataTable
       dt.Load(cmd.ExecuteReader)
       With dgvmodstud
           .AutoGenerateColumns = True
           .DataSource = dt
       End With
       Dim currentModuleCode As String = String.Empty
       For i = 0 To dgvmodstud.Rows.Count - 1
           If dgvmodstud.Rows(i).Cells(0).Value = currentModuleCode Then
               dgvmodstud.Rows(i).Cells(0).Value = String.Empty
           Else
               currentModuleCode = dgvmodstud.Rows(i).Cells(0).Value
           End If
       Next i
       conn.Close()
       cmd.Dispose()



有人帮我这个?


anyone help me with this?

推荐答案

use  subquery


这篇关于datagrid行计数器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!

09-27 10:51