resultsetform.cs

来自「Microsoft Mobile Development Handbook的代码」· CS 代码 · 共 57 行

CS
57
字号
using System;
using System.Data.SqlServerCe;
using System.Windows.Forms;

namespace MobileDevelopersHandbook
{
    public partial class ResultSetForm : Form
    {
        private MobileDevelopersHandbook.MyResultSetsResultSets.ProductResultSet productResultSet;
        private MobileDevelopersHandbook.MyResultSetsResultSets.ProductCategoryResultSet productCategoryResultSet;
    
        public ResultSetForm()
        {
            InitializeComponent();
        }

        private void ResultSetForm_Load(object sender, EventArgs e)
        {
            // TODO: Delete this line of code to remove the default AutoFill for 'MobileDevelopersHandbook.MyResultSetsResultSets.ProductResultSet'.
            //productResultSet = new MobileDevelopersHandbook.MyResultSetsResultSets.ProductResultSet();
            //productResultSet.Bind(this.productResultSetBindingSource);
            // TODO: Delete this line of code to remove the default AutoFill for 'MobileDevelopersHandbook.MyResultSetsResultSets.ProductCategoryResultSet'.
            productCategoryResultSet = new MobileDevelopersHandbook.MyResultSetsResultSets.ProductCategoryResultSet();
            productCategoryResultSet.Bind(this.productCategoryResultSetBindingSource);

            // Setup the child records data source
            SetProductResultSet();
        }

        private void productCategoryResultSetDataGrid_CurrentCellChanged(object sender, EventArgs e)
        {
            SqlCeResultSet oldRS = this.productResultSet;

            // User has clicked on the grid
            SetProductResultSet();

            // Dispose of the redundant SqlCEResultSet
            oldRS.Dispose();
        }

        private void SetProductResultSet()
        {
            // Find the ProductCategoryID of the selected record
            int prodCatID = (int)((RowView)this.productCategoryResultSetBindingSource.Current).UpdatableRecord["ProductCategoryID"];

            // Create new resultset using our 'custom' constructor
            productResultSet = new MyResultSetsResultSets.ProductResultSet(false);
            // Filter on the index we created earlier, and only the 
            // required ProductCategoryID
            productResultSet.Open("ProductCategoryID_idx", prodCatID, prodCatID);

            // Bind the BindingSource
            productResultSet.Bind(this.productResultSetBindingSource);
        }

    }
}

⌨️ 快捷键说明

复制代码Ctrl + C
搜索代码Ctrl + F
全屏模式F11
增大字号Ctrl + =
减小字号Ctrl + -
显示快捷键?