C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法
本文實(shí)例講述了C#實(shí)現(xiàn)綁定DataGridView與TextBox之間關(guān)聯(lián)的方法。分享給大家供大家參考。具體實(shí)現(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è)計(jì)有所幫助。
相關(guān)文章
C#創(chuàng)建一個(gè)小型Web Server(Socket實(shí)現(xiàn))
這篇文章主要介紹了關(guān)于C#利用Socket實(shí)現(xiàn)創(chuàng)建一個(gè)小型Web Server的相關(guān)資料,文中通過示例代碼介紹的很詳細(xì),需要的朋友可以參考借鑒,下面來一起看看吧。2017-02-02DataGridView實(shí)現(xiàn)點(diǎn)擊列頭升序和降序排序
這篇文章介紹了DataGridView實(shí)現(xiàn)點(diǎn)擊列頭升序和降序排序的方法,文中通過示例代碼介紹的非常詳細(xì)。對大家的學(xué)習(xí)或工作具有一定的參考借鑒價(jià)值,需要的朋友可以參考下2022-02-02C#中IEnumerable、ICollection、IList、List之間的區(qū)別
這篇文章主要介紹了C#中IEnumerable、ICollection、IList、List之間的區(qū)別,本文分別分析了它的實(shí)現(xiàn)源碼,從而總結(jié)出了它們之間的關(guān)系和不同之處,需要的朋友可以參考下2015-06-06C#實(shí)現(xiàn)把dgv里的數(shù)據(jù)完整的復(fù)制到一張內(nèi)存表的方法
這篇文章主要介紹了C#實(shí)現(xiàn)把dgv里的數(shù)據(jù)完整的復(fù)制到一張內(nèi)存表的方法,需要的朋友可以參考下2014-08-08WPF實(shí)現(xiàn)動(dòng)畫效果(三)之時(shí)間線(TimeLine)
這篇文章介紹了WPF實(shí)現(xiàn)動(dòng)畫效果之時(shí)間線(TimeLine),對大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-06-06