开发者

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()
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜