Yes, it worked like a charm.
I decided to use an array of typed datasets - one for each day. It's the same idea as the bindingsource, but I'm more familiar with datasets, so I opted for them.
Thanks again for the nudge in the right direction, Bonnie.
This is much better than plan B (no bindings) would have been.
Here's what the final result looks like.
for (int i = 0; i <= DaysInMonth - 1; i++)
{
ArrayCapacityTB[i] = new TextBox();
SetTextBox(ArrayCapacityTB[i], ArrayMonthDay[i].Left - 40, ArrayMonthDay[i].Top + 25, 25);
ArrayCapacityTB[i].DataBindings.Add("Text", ArrayRefds[i], "capacitycalendar.capacity");
}
>That should work. I'd use Lists rather than Arrays (for your TextBoxes too), but peformance-wise, I don't know if it matters (Lists vs Arrays).
>
>~~Bonnie
>
>
>
>>Thanks, Bonnie
>>
>>I had read something about the positioning and didn't understand it. This clarifies it.
>>
>>My textboxes are in an array. I'm wondering if I can put the binding sources in another array do it all in a for loop.
>>
>>I'll give it a try.
>>
>>Thanks again.
>>
>>
>>
>>>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.
Anyone who does not go overboard- deserves to.
Malcolm Forbes, Sr.