Datarowview + listbox + Currencyformat

torg

Well-known member
Joined
Nov 7, 2002
Messages
60
Location
Norway
I`ve got lstAmount. I whish to show the sum as a currencyformat in the listbox. How do I do that?

Code:
adInCome = New OleDb.OleDbDataAdapter("SELECT sum(tblIncome.Amount) as Total from tblIncome ;", Me.OleDbConnection)
 Try
                    adInCome .Fill(dsIncome, "dtInncome")
                Catch ex As OleDb.OleDbException
                    MessageBox.Show(ex.Message)
                End Try
                Me.OleDbConnection.Close()
                lstAmount.DataSource = dsIncome.Tables("dtIncome")
                lstAmount.ValueMember = "Total"
 
I dont know if theres a built-in way to do it. You can loop through the DataTable and add each item, of course, and format each Total as currency as you go (use the ToString("c") method).

-Nerseus
 
Thank You.
I used this code to achieve what I wanted to achieve
Code:
Dim DataView1 As DataView = New DataView()
        With DataView1
            .Table = dsUtgiftspost.Tables("dtUtgiftspost")
        End With

        Dim drv As DataRowView
        Dim s As String = ""
        For Each drv In DataView1
            s &= drv("Total").ToString & "   "
        Next
        lstBelop.Items.Add(FormatCurrency(s)) << Sets the currency format
 
If you dont need the DataView for anything else I wouldnt use it. Also, dont you want each item to be a separate string? Try something like this:
Code:
        Dim dr As DataRow
        For Each dr In dsUtgiftspost.Tables("dtUtgiftspost").Rows
            lstBelop.Items.Add(dr("Total").ToString("c"))
        Next

-Nerseus
 
Back
Top