簡體   English   中英

vb.net datagridview以數據集作為數據源

[英]vb.net datagridview with dataset as datasource

我的問題是,有沒有一種方法可以過濾數據集中的記錄並使用該記錄來填充datagridview? 例如,一個數據表(包含3列: IDStudentNameGender )填充有學生列表。 我有兩個形式為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

有沒有不使用循環的方法?

就在這里。 您需要做的就是使用SELECT過濾數據集。

例如,

DatagridView1.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'M'")
DatagridView2.Datasource = xSet.Tables("StudentList").SELECT("Gender = 'F'")

簡要說明:

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

更新

屏幕截圖

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM