Click here to Skip to main content
15,896,429 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
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.
Posted

1 solution

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");
 
Share this answer
 
Comments
[no name] 10-Sep-11 14:57pm    
Wow! Not difficult at all!
Thank you so much!
Pradeep Shukla 10-Sep-11 15:08pm    
ur welcome...:-)

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900