[英]vb.net datagridview with dataset as datasource
我的問題是,有沒有一種方法可以過濾數據集中的記錄並使用該記錄來填充datagridview? 例如,一個數據表(包含3列: ID
, StudentName
, Gender
)填充有學生列表。 我有兩個形式為DatagridView1
和Datagridview2
。 DatagridView1
就是學生的名單,其中Gender
等於M
和DatagridView2
就是學生的名單,其中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.