简体   繁体   中英

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.

The real question I have here is that I don't know how to populate the dataGridView with the files from that 2nd DataSet. 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.

You can easily filter data by using RowFilter and than you assign that filter data to the datagrid control easily.

For example syntax of Rowfilter:

dataset_filter.Tables[0].DefaultView.RowFilter 

For more details you can check article : DataView RowFilter Syntax [C#]

OR

you can make use of DataSet to Linq and do something as below

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;

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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