Plateforme Level Extreme
Abonnement
Profil corporatif
Produits & Services
Support
Légal
English
Binding to a row in a data table
Message
De
06/08/2012 12:31:21
 
 
À
06/08/2012 12:07:20
Information générale
Forum:
ASP.NET
Catégorie:
Code, syntaxe and commandes
Versions des environnements
Environment:
C# 3.0
Divers
Thread ID:
01549963
Message ID:
01550008
Vues:
45
Bonnie

Can I use intellisense to access columns with the bindingsource?
One of the reasons I opted for the typed dataset/datatable idea was that I knew that I could use intelliense in some of my calcuations with the columns.
Frankly, with 31 rows, I wasn't considering performance, although your point is well taken.
This particular application won't have much usage, but the approach might be the basis for other applications at the client that would have more usage.



>>Thanks again for the nudge in the right direction, Bonnie
>
>You're welcome, Bill. But, I'm going to give you an even bigger nudge. Keep reading ...
>
>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.
>
>Hmmm ... I guess I don't get that decision. You already had a DataSet (Typed I assume). It already had a Typed DataTable with 31 rows of data. Now you're duplicating all of that data 31 times in an array? Or are you copying one row at a time into 31 new DataTables? Either way, that doesn't make sense because it's a lot of extra work/processing for no gain. Really, you should try the BindingSource idea ... it will be a lot less work and much cleaner code.
>
>Just my 2 cents ...
>
>~~Bonnie
>
>
>
>
>>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.
Précédent
Répondre
Fil
Voir

Click here to load this message in the networking platform