简体   繁体   English

通过下拉列表使用数据集填充dataGridView

[英]Populating a dataGridView using DataSets through a Drop-down List

I'm suppose to make two simple DataSets for a small movie database for a school assignment. 我想为一个用于学校作业的小型电影数据库制作两个简单的数据集。 The assignment also says that I should be able to select an item from a drop down list (populated with one of the DataSets that includes the Movie name) which will filter the results of a dataGridView (populated with the other DataSet) and display the names and roles of the people in that movie. 作业还说,我应该能够从下拉列表中选择一个项目(由一个包含Movie名称的DataSet填充),该项目将过滤dataGridView的结果(由另一个DataSet填充)并显示名称和电影中人们的角色。

The real question I have here is that I don't know how to populate the dataGridView with the files from that 2nd DataSet. 我这里真正的问题是,我不知道如何用第二个DataSet中的文件填充dataGridView。 I also don't know how to make the SQL filter that changes the data in the dataGridView based on the movie in the drop down, but my main concern is just getting the dataGridView populated at the moment. 我还不知道如何使SQL过滤器根据下拉列表中的影片来更改dataGridView中的数据,但是我主要关心的只是此刻填充dataGridView。

You can easily filter data by using RowFilter and than you assign that filter data to the datagrid control easily. 您可以使用RowFilter轻松筛选数据,然后轻松地将该筛选数据分配给datagrid控件。

For example syntax of Rowfilter: 例如Rowfilter的语法:

dataset_filter.Tables[0].DefaultView.RowFilter 

For more details you can check article : DataView RowFilter Syntax [C#] 有关更多详细信息,请查看以下文章: DataView RowFilter语法[C#]

OR 要么

you can make use of DataSet to Linq and do something as below 您可以将DataSet用于Linq并执行以下操作

DataTable orders = dataSet.Tables["SalesOrderDetail"];

EnumerableRowCollection<DataRow> query = from order in orders.AsEnumerable()
                                         where order.Field<Int16>("OrderQty") > 2 && order.Field<Int16>("OrderQty") < 6 
                                         select order;

DataView view = query.AsDataView();

bindingSource1.DataSource = view;

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM