Click here to Skip to main content
12,951,983 members (64,657 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Can anyone tell me the codings as to how to read from listview and generate them on listbox using call function.
I know it's possible to read from database and generate them onto listbox but how about listview using call function. here's a sample of what how a listbox is able to read from a database and generate them on the listbox.

the listbox is reading from database, how does one make it to read from an active listview.


Private Sub frmReceipt_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim strConnection As String = "Provider=Microsoft.Jet.OLEDB.4.0;Data Source= luggageb.mdb"
        Dim objConnection As New OleDbConnection(strConnection)
 
        Dim fmtStr As String = "{0, -14} {1, -8}  {2, -1} "
        Dim fmtstr1 As String = "{0, -14} {1,-8} {2, -1} {3, -10}"
        Dim fmtstr2 As String = "{0,-34}{1,-18}"
        Dim fmtstr3 As String = "{0, -16} {1,-10} {2, -5} {3, -1:C}"
        Try
 
            objConnection.Open()
        Catch OleDbExceptionErr As OleDbException
            MessageBox.Show(OleDbExceptionErr.Message)
        Catch InvalidOperationErr As InvalidOperationException
            MessageBox.Show(InvalidOperationErr.Message)
 
        End Try
 
        Dim strSQL As String = "SELECT Transaction_ID, Purchase_ID, ItemNo, ItemPrice, ItemQuantity, TotalPrice FROM tblPurchase WHERE Transaction_ID = '" & frmPurchaseItem.mskTransaction.Text & "'"
        Dim objCommand As New OleDbCommand(strSQL, objConnection)
 

        Dim objDataAdapter As New OleDbDataAdapter(objCommand)
        Dim dgvTransaction As New DataTable("tblPurchase")
        objDataAdapter.Fill(dgvTransaction)
 

 
        objConnection.Close()
        objConnection.Dispose()
        objConnection = Nothing
        objCommand.Dispose()
        objCommand = Nothing
        objDataAdapter.Dispose()
        objDataAdapter = Nothing
 
        ListBox1.Items.Add("                    ##########                     ")
        ListBox1.Items.Add("               ####################                      ")
        ListBox1.Items.Add("=======================================================")
 
        Call ListBox1.Items.Add(String.Format(fmtStr, "Date Purchase : " & frmPurchaseItem.dtpPurchaseDate.Text, " ", " ", " "))
        Call ListBox1.Items.Add(String.Format(fmtStr, "Cashier Name  : " & frmPurchaseItem.mskStaffID.Text, " ", " ", " "))
        Call ListBox1.Items.Add(String.Format(fmtStr, "Receipt No:  : " & frmPurchaseItem.mskTransaction.Text, " ", " ", " "))
        Call ListBox1.Items.Add(String.Format(fmtStr, "Payment Method:  : " & frmPurchaseItem.cbPaymentMenthod.Text, " ", " ", " "))
 
        ListBox1.Items.Add(" ")
        ListBox1.Items.Add("-------------------------------------------------------------------------- ")
        Call ListBox1.Items.Add(String.Format(fmtstr1, "Purchase_ID", "Item No ", "Quantity ", "Price"))
        ListBox1.Items.Add("-------------------------------------------------------------------------- ")
 
        For Each Row As DataRow In dgvTransaction.Rows
 
            'FOR CALCULATION
 

            Call ListBox1.Items.Add(String.Format(fmtstr3, Row.Item("Purchase_ID"), Row.Item("ItemNo"), Row.Item("ItemQuantity"), FormatCurrency(Row.Item("TotalPrice"))))
            'Call ListBox1.Items.Add(frmPurchaseItem.mskItemID.Text)
            'Call ListBox1.Items.Add(frmPurchaseItem.txtItemQuantity.Text)
            'Call ListBox1.Items.Add(frmPurchaseItem.txtItemPrice.Text)
            'ListBox1.Items.Add(" ")
 
        Next
 

        ListBox1.Items.Add(" ")
        ListBox1.Items.Add(" ")
 
        ListBox1.Items.Add(String.Format(fmtstr2, "Total Amount (B$)", FormatCurrency(frmPurchaseItem.lblTotalAmount.Text)))
        ListBox1.Items.Add(String.Format(fmtstr2, "Cash", FormatCurrency(frmPurchaseItem.txtPaid.Text)))
        ListBox1.Items.Add(String.Format(fmtstr2, "Change Amount (B$)", FormatCurrency(frmPurchaseItem.lblChange2.Text)))
 

 
        ListBox1.Items.Add(" ")
        ListBox1.Items.Add(" ")
 
        ListBox1.Items.Add("=============================================================")
        ListBox1.Items.Add("             Goods Are Not Returnable                   ")
        ListBox1.Items.Add("           Thank You Please Come Again                 ")
        ListBox1.Items.Add("=============================================================")
 

 
        dgvTransaction.Dispose()
        dgvTransaction = Nothing
    End Sub
Posted 13-May-12 16:45pm
Comments
SAKryukov 13-May-12 23:33pm
   
What is that supposed to mean: "using call function"? "List box able to read from database"? What did you try? What's the problem?
--SA

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 13 May 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100