2012-01-13 18 views
1

私の質問は、データセット内のレコードをフィルタリングし、そのレコードを使用してdatagridviewを埋め込む方法はありますか?例えば、データテーブル(3列:IDStudentNameGender)は、学生リストで埋められます。私は2つのデータグリッド、すなわちDatagridView1Datagridview2を持っています。 DatagridView1は、GenderMと等しい学生リストとDatagridView2がどこの学生リストであるかを示します。ここで、GenderFです。vb.net datagridview with datasource

私の現在のソリューションでは、私はループを使用しています。

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 

ループを使用しない方法がありますか?

答えて

4

はい、あります。 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 

UPDATE

Screen Shot

+0

は、ジョンをありがとう! –

関連する問題