So here's what I have, Ive got a Listbox which displays a data/record from a SQL database, it displays "Amount" and only numbers would appear. it has a datasource.
Goal: I'd Like to get the total sum of those numbers from the Listbox and Display it to a textbox automatically or by button click event.
I thought of two ways to do this, but I don't have a clue on what to do.
1. I tried summing it all up on that exact Listbox and display the total on the textbox, here's the code that i came up with..
Dim sum As Double
For x As Integer = 0 To ListBox1.Items.Count - 1
sum += CDbl(ListBox1.Items(x))
TotalTextBox.Text = sum.ToString
But the data im working with is from a database, so i got this error:
Conversion from type 'DataRowView' to type 'Double' is not valid.
2. I thought of having another Listbox and "Copy" the contents shown on the Listbox1 and then sum it all up on the Listbox2, then lastly display the Total on the Textbox. I did a little research on how to accomplish that but all the clue i found is that i have to disconnect the listbox data from the datasource from being bound, and reconnect it again.. I really don't have any idea on how i could do that with an SQL database.
Here's a quick flow on what im trying to accomplish to make things clear for you guys.
Record from Database -----Displays on---> Listbox1 -----User Clicks--> Button1 ----Displays Total sum on----> Textbox1