使用数据集作为数据源的vb.net datagridview

1 vb.net datagridview dataset

我的问题是,有没有办法过滤数据集中的记录并使用该记录来填充datagridview?例如,一个数据表(3列:ID,StudentName,Gender)填充有学生的列表.我有两个数据网格形式即DatagridView1Datagridview2.DatagridView1就是学生的列表,Gender等于MDatagridView2就是其中的学生的名单Gender等于F.

在我目前的解决方案中,我正在使用循环.

For each iStud as datarow in iDataset.Tables(0).Rows
      IF iStud.Item("Gender").ToString = "M" Then
            'add this record to DatagridView1
      Else
            'add this record to DatagridView2
      End If
Next
Run Code Online (Sandbox Code Playgroud)

有没有使用循环的方法?

Joh*_*Woo 5

就在这里.您需要做的就是使用过滤数据集SELECT.

例如,

DatagridView1.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'M'")
DatagridView2.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'F'")
Run Code Online (Sandbox Code Playgroud)

简要说明:

xSet          is the name of the Dataset
StudentList   is the name of the Datatable
Gender        is the name of the Column where you want to filter
Run Code Online (Sandbox Code Playgroud)

UPDATE

屏幕截图