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);
}
}
}
希望本文所述對(duì)大家的C#程序設(shè)計(jì)有所幫助。
相關(guān)文章
c#實(shí)現(xiàn)斷點(diǎn)續(xù)傳功能示例分享
這篇文章主要介紹了c#實(shí)現(xiàn)的斷點(diǎn)續(xù)傳功能示例,斷點(diǎn)續(xù)傳就是在上一次下載時(shí)斷開的位置開始繼續(xù)下載。在HTTP協(xié)議中,可以在請(qǐng)求報(bào)文頭中加入Range段,來表示客戶機(jī)希望從何處繼續(xù)下載,下面是示例,需要的朋友可以參考下2014-03-03
使用C#實(shí)現(xiàn)一個(gè)簡單的繪圖工具
這篇文章主要為大家詳細(xì)介紹了如何使用C#開發(fā)的簡單繪圖工具,可以將簽名簡單繪圖后的效果以圖片的形式導(dǎo)出,有需要的小伙伴可以跟隨小編一起學(xué)習(xí)一下2024-02-02
C#處理類型和二進(jìn)制數(shù)據(jù)轉(zhuǎn)換并提高程序性能
這篇文章介紹了C#處理類型和二進(jìn)制數(shù)據(jù)轉(zhuǎn)換并提高程序性能的方法,對(duì)大家的學(xué)習(xí)或者工作具有一定的參考學(xué)習(xí)價(jià)值,需要的朋友們下面隨著小編來一起學(xué)習(xí)學(xué)習(xí)吧2022-04-04
C#實(shí)現(xiàn)十六進(jìn)制與十進(jìn)制相互轉(zhuǎn)換以及及不同進(jìn)制表示
在C#中十進(jìn)制和十六進(jìn)制轉(zhuǎn)換非常簡單,下面這篇文章主要給大家介紹了關(guān)于C#實(shí)現(xiàn)十六進(jìn)制與十進(jìn)制相互轉(zhuǎn)換以及及不同進(jìn)制表示的相關(guān)資料,文中通過示例代碼介紹的非常詳細(xì),需要的朋友可以參考下2022-10-10
C#使用迭代法實(shí)現(xiàn)Fibnaci數(shù)列
這篇文章主要介紹了C#使用迭代法實(shí)現(xiàn)Fibnaci數(shù)列的方法,較為詳細(xì)的分析了Fibnaci數(shù)列的原理與迭代法實(shí)現(xiàn)技巧,需要的朋友可以參考下2015-05-05
c#實(shí)現(xiàn)網(wǎng)頁圖片提取工具代碼分享
c#實(shí)現(xiàn)網(wǎng)頁圖片提取工具代碼分享,大家參考使用吧2013-12-12
c#方法中調(diào)用參數(shù)的值傳遞方式和引用傳遞方式以及ref與out的區(qū)別深入解析
以下是對(duì)c#方法中調(diào)用參數(shù)的值傳遞方式和引用傳遞方式,以及ref與out的區(qū)進(jìn)行了詳細(xì)的分析介紹,需要的朋友可以過來參考下2013-07-07

