Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Binding to a row in a data table
Message
From
04/08/2012 17:24:54
 
 
To
04/08/2012 15:45:13
General information
Forum:
ASP.NET
Category:
Coding, syntax and commands
Environment versions
Environment:
C# 3.0
Miscellaneous
Thread ID:
01549963
Message ID:
01549965
Views:
56
There's no easy, straightforward way to do it, but it is do-able. Databinding doesn't really work that way, so you've got to kludge it a bit ... this will work:

1) Create 31 BindingSource objects.
2) Set the DataSource of each BindingSource object to your DataTable.
3) Set the Position of the first BindingSource object to 0, the second to 1, the third to 2, etc.
4) For each TextBox, set the DataBinding in the usual way:
   this.txtDay1.DataBindings.Add("Text", bs0, "TheData");
   this.txtDay2.DataBindings.Add("Text", bs1, "TheData");
   this.txtDay3.DataBindings.Add("Text", bs2, "TheData");
It might be more trouble than it's worth, unless you might use each of those 31 BindingSource objects for displaying some other data for each of those 31 rows.

~~Bonnie

>I have a winform with up to 31 textboxes (it's a calendar.)
>Each box relates to data from a specific row in a data table (0-30.)
>I can't figure out how to add a databinding to a textbox that points to a specific row in the data table.
>I can accomplish what I'm trying to do another way, but I'd like to use databinding if I could.
>Any clues will be appreciated.
Bonnie Berent DeWitt
NET/C# MVP since 2003

http://geek-goddess-bonnie.blogspot.com
Previous
Next
Reply
Map
View

Click here to load this message in the networking platform