BindingNavigatorをWinフォームの制御[データセット] [] [] [DataGridViewののBindingSource]

基本的な導入

制御データのタイプ、データ・ロード・バインディングアプリケーションの便利広い範囲、具体的に拡張、独自の例を参照します。

チャンは、プロパティを設定します

BindingNavigatorを-のBindingSource:データ・ソース、対応する動作を実行するためのデフォルトのバインディングエントリボタンに基づきます。

BindingNavigatorを-アイテム:アイテムのセットを表示します。

データセット-テーブル:データテーブル内に設定データを集計。

BindingSource -データソース: 文字列。

BindingSource -フィルタは、並べ替え:データ・ソースのソート、フィルタリングします。

DataGridViewの-データソース:今日の日付を表示するかどうかを示す制御のカレンダー下;

DataGridViewの-列、行:列のデータソースは、ターゲットラインを設定します。

 

事例

 

関連するコード

        //控件数据绑定
        private void btn_serachData_Click(object sender, EventArgs e)
        {
            string strValue = txt_sql.Text.Trim();
            if (!string.IsNullOrWhiteSpace(strValue))
            {
                //获取数据源绑定DataSet
                dataSet1 = Helpers.DBHelper.GetDataBySql(strValue);
                if (Helpers.UtilityHelper.GetRowCount(dataSet1) > 0)
                {
                    //绑定DataGridView
                    dataGridView1.DataSource = dataSet1.Tables[0];
                    
                    //绑定BindingSource
                    bindingSource1.DataSource = dataSet1;
                    bindingSource1.DataMember = dataSet1.Tables[0].TableName;

                    //指定数据列绑定TextBox
                    txt_code.DataBindings.Add("Text", bindingSource1, "SITE_CODE");
                    txt_name.DataBindings.Add("Text", bindingSource1, "SITE_NAME");

                    //绑定BindingNavigator
                    bindingNavigator1.BindingSource = bindingSource1;
                }
            }
        }

        //dataGridView数据选择联动
        private void textBox1_TextChanged(object sender, EventArgs e)
        {
            if (dataGridView1 != null && !string.IsNullOrWhiteSpace(txt_code.Text))
            {
                //切换数据时,定位选中列表行
                dataGridView1.ClearSelection();
                dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
                foreach (DataGridViewRow row in dataGridView1.Rows)
                {
                    string str = row.Cells["SITE_CODE"].Value.ToString();
                    if (str.Equals(txt_code.Text))
                    {
                        row.Selected = true;
                        return;
                    }
                }
            }
        }

 

おすすめ

転載: www.cnblogs.com/ljhandsomeblog/p/11246094.html