VB 2008 or VB 2010 Dataset help
I have three forms similar to the one in the link. I want add a Total textbox to every form. The total will add the v开发者_如何转开发alues that will be entered in the montant textbox. So the total will take the specific value of that texbox for all the entries that the user will have and add them. How I can do so???? Thanks http://i1006.photobucket.com/albums/af189/diaboloent/OneForm.jpg
Put all the textboxes where the user will enter a value inside a common container like a groupbox or panel control. Then use code like this to total up the values:
Dim sum As Integer = 0
For Each box As TextBox In MyContainer.Controls.OfType(Of TextBox)()
sum += Integer.Parse(box.Text)
Next box
Total.Text = sum.ToString()
You can even get this down to a one-liner:
Total.Text = MyContainer.Controls.OfType(Of TextBox)().Select(Function(s) Integer.Parse(s.Text)).Sum()
精彩评论