C#實現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
更新時間:2015年08月20日 16:57:29 作者:我心依舊
這篇文章主要介紹了C#實現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法,涉及C#綁定控件關(guān)聯(lián)性的相關(guān)技巧,具有一定參考借鑒價值,需要的朋友可以參考下
本文實例講述了C#實現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法。分享給大家供大家參考。具體實現(xiàn)方法如下:
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace System.Windows.Forms.Samples
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
/* Create a DataSet with 1 DataTable */
DataSet dataSet = new DataSet();
DataTable dataTable = dataSet.Tables.Add("Numbers");
dataTable.Columns.Add("ID", typeof(int));
dataTable.Columns.Add("Name", typeof(string));
dataTable.Rows.Add(0, "Zero");
dataTable.Rows.Add(1, "One");
CurrencyManager cm;
/* Get a CurrencyManager */
// cm = (this.BindingContext[dataSet, "Numbers"] as CurrencyManager);
/* This gets a different CurrencyManager */
cm = (this.BindingContext[dataTable] as CurrencyManager);
/* Bind left DataGridView and TextBox */
this.dataGridView1.DataSource = dataSet;
this.dataGridView1.DataMember = "Numbers";
this.textBox1.DataBindings.Add("Text", dataSet, "Numbers.Name", true);
/* Bind left DataGridView and TextBox */
this.dataGridView2.DataSource = dataTable;
this.textBox2.DataBindings.Add("Text", dataTable, "Name", true);
}
}
}
希望本文所述對大家的C#程序設(shè)計有所幫助。
相關(guān)文章
C#處理類型和二進(jìn)制數(shù)據(jù)轉(zhuǎn)換并提高程序性能
這篇文章介紹了C#處理類型和二進(jìn)制數(shù)據(jù)轉(zhuǎn)換并提高程序性能的方法,對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
C#實現(xiàn)十六進(jìn)制與十進(jìn)制相互轉(zhuǎn)換以及及不同進(jìn)制表示
在C#中十進(jìn)制和十六進(jìn)制轉(zhuǎn)換非常簡單,下面這篇文章主要給大家介紹了關(guān)于C#實現(xiàn)十六進(jìn)制與十進(jìn)制相互轉(zhuǎn)換以及及不同進(jìn)制表示的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-10-10
c#方法中調(diào)用參數(shù)的值傳遞方式和引用傳遞方式以及ref與out的區(qū)別深入解析
以下是對c#方法中調(diào)用參數(shù)的值傳遞方式和引用傳遞方式,以及ref與out的區(qū)進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過來參考下2013-07-07

