How do I loop through a multi-column listbox in WPF?

Hello Experts,

I am a beginner with WPF. I fear this may sound like a silly question.

I have a listbox with two columns. Each listbox item contains a horizontal stacked panel which in turn contains textblocks.

The listbox is empty, with each listbox item being added by the end-user through a couple of textboxes placed elsewhere. The first column accepts strings, and the second column accepts only percentages.

(I have attached a relevant portion of the event sub where a user is adding new rows.)

I would like to be able to check every time the above event is fired that the column of percentages does not exceed 100%. I have a couple of labels below the listbox itself where I would like to show the running total and the remainder. However, how can I loop through the second column of percentages to show the running total and remainder?

I would appreciate any sort of guidance towards a solution on this. Thank you very much.
Private Sub btnAddItem_Click(sender As System.Object, e As System.Windows.RoutedEventArgs) Handles btnAddSplit.Click


            Dim ListBoxItemName As New TextBlock
            ListBoxItemName.Text = Name.Text
            ListBoxItemName.Width = 170

            Dim ListBoxItemValue As New TextBlock
            ListBoxItemValue.Text = SplitValue.Text
            ListBoxItemValue.Width = 70

            Dim ListBoxStackPanel As New StackPanel
            ListBoxStackPanel.Orientation = Orientation.Horizontal

            Dim NewEntry As New ListBoxItem
            NewEntry.Content = ListBoxStackPanel



    End Sub

Open in new window

Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Why not validate the percentage value in the above code rather than looping through list? Assuming that SplitValue.Text is the percentage, do a simple > 100 check and show error message if it is. You can also do the total in the above code. Maintain a class level variable and add to it in the above code.

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
MrMoneypennyAuthor Commented:
Thanks for your tip, I willl set about doing just that.
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
Visual Basic.NET

From novice to tech pro — start learning today.

Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.