如何将文本框绑定到数据表的指定单元格? [英] How to bind a textbox to a specified cell of a datatable?

查看:69
本文介绍了如何将文本框绑定到数据表的指定单元格?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个文本框和一个数据表,其中已包含一些数据,我希望将文本框的Text属性绑定到数据表中某些指定单元格的值,我想我们必须使用文本框,但是如何进行详细操作仍然是我的秘密.这里的任何人都可以为我提供完整的解释和示例代码吗?
谢谢大家!
祝大家程序员幸福快乐.

I have a textbox and a datatable with some already data in it, I want the Text property of the textbox to be bound to some specified cell''s value in the datatable, I guess we have to use the DataBindings property of the textbox but the how to do it in details is still a secret to me. Could anyone here please help me with full explanation and example code?
Thank you all!
Wish you all programmers happiness and health.

推荐答案

这应该像这样:

DataTable dtSource =新的DataTable("dtDataSource");
dtSource.Columns.Add("ID",typeof(Int32));
dtSource.Columns.Add("Name",typeof(string));
dtSource.Columns.Add("Address",typeof(string));
DataRow dr = dtSource.NewRow();
dr [0] = 1;
dr [1] ="Roger";
dr [2] ="NewYork";
dtSource.Rows.Add(dr);

tb.DataBindings.Add("Text",dtSource,"Name");
This should be like this:

DataTable dtSource = new DataTable("dtDataSource");
dtSource.Columns.Add("ID",typeof(Int32));
dtSource.Columns.Add("Name",typeof(string));
dtSource.Columns.Add("Address",typeof(string));
DataRow dr = dtSource.NewRow();
dr[0] = 1;
dr[1] = "Roger";
dr[2] = "NewYork";
dtSource.Rows.Add(dr);

tb.DataBindings.Add("Text",dtSource,"Name");


这篇关于如何将文本框绑定到数据表的指定单元格?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆