2 Attachment(s)
[RESOLVED] sum listbox items
Iam adding a elemnet from a xml file into listbox
Code:
Option Strict On
Option Explicit On
Option Infer Off
Imports System.IO
Imports System.Xml
Imports System.Net
Imports System.Windows.Forms.VisualStyles.VisualStyleElement.ListView
Public Class Form1
Dim path As String = ("F:\ESS_Contacts\dsContactsSUBS.xml")
Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
End Sub
Private Sub Button1_Click(sender As Object, e As EventArgs) Handles Button1.Click
Dim ds As New DataSet
ds.ReadXml(path)
ListBox1.DataSource = ds.Tables("Contacts")
ListBox1.DisplayMember = "amount"
End Sub
Private Sub Button2_Click(sender As Object, e As EventArgs) Handles Button2.Click
Dim totall As Double
For Each item As Double In ListBox1.Items
totall += item
Next
txtTotalCost.Text = CType(totall, String)
End Sub
End Class
I am then trying to sum the list but keeping getting errors
System.InvalidCastException: 'Conversion from type 'DataRowView' to type 'Double' is not valid.'
I have worked out its because of the way i add the data
Ive tried heaps of examples but always get the same error.
ps. ignore images, seems to be no way to delete once uploaded...