Question help me to code this..

trialer

Well-known member
Joined
Oct 4, 2010
Messages
64
Programming Experience
1-3
97659297.jpg


VB.NET:
With lvList
            .Clear()
          [COLOR="#008000"]  [I]'loading data from database[/I][/COLOR]
            .View = View.Details
            .FullRowSelect = True
            .GridLines = True
            .Columns.Add("Customer ID", 50)
            .Columns.Add("Name", 100)
            .Columns.Add("Address", 100)
            .Columns.Add("Existing Balance", 50)
            FillListView(lvlist, GetData(sSql))
            .Columns.Add("Remaining Balance")
           [I] 'calculation[/I]
            calc = pbal
            i1 = 1000
            calc = pbal + i1
          [I][COLOR="#008000"]  'adding to listview[/COLOR][/I]
            Dim lst As New ListViewItem(cid)
            lst.SubItems.Add("")
            lst.SubItems.Add("")
            lst.SubItems.Add("")
            lst.SubItems.Add(calc.ToString)
            lvlist.Items.Add(lst)
        End With


how do i align the the total with its corresponding customer ID,


please help me how to add 1000 to each prevbal and put it in the column remainingbal


thanks in advance!
 
Last edited:
Why not add the Remaining Balance data as you load the rest? That would make the most sense. You're already looping through the data, so calculate and add the Remaining Balance as you go.

If you don't do that then you will have to loop through the existing items, not add new items. You need to loop through the items already in the ListView, get the data from those items and add the Remaining Balance to those items.
 
its just like this the result.. i can only compute the first record then the rest it doesnt compute.

aw2u.jpg
 
here's my vb code
VB.NET:
 Connect()
        ds = New DataSet
        dv = New DataView
        Dim ad As New SqlDataAdapter("SELECT CustomerID, Name,Address, PrevBal FROM table_billing where Address='" & ComboBox1.Text & "'", con)
        Dim cmd As New SqlCommand("SELECT * FROM table_billing ", con)
        Dim dr As SqlDataReader = cmd.ExecuteReader
        If dr.Read Then
            For Each row As System.Windows.Forms.DataGridViewRow In DataGridView1.Rows
                row.Cells("CustomerID").Value = dr("CustomerID")
                row.Cells("Name").Value = dr("Name")
                row.Cells("Address").Value = dr("Address")
                row.Cells("PrevBal").Value = dr("PrevBal")
                row.Cells("NewBal").Value = dr("PrevBal") + 1000
            Next
            dr.Close()
        End If
        ad.Fill(ds, "Billing2")
        dv.Table = ds.Tables("Billing2")
        Me.DataGridView1.DataSource = dv
        Disconnect()

my code doesn't show the result in newbal column
 
The last thing you do is set the DataSource, so anything that was already in the grid is removed and the grid is populated with that data.

By the way, given that you started out with a ListView, pointing out that you are now using a DataGridView would be a good idea. You've changed horses mid-stride without telling us so we will continue to give you advice relating to the first horse. Remember that we know nothing about what you're doing other than what you tell us, so please tell us EVERYTHING that is relevant.
 
the first horse..

VB.NET:
Public Class Form1

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        With lvList
            .Clear()
            'loading data from database
            .View = View.Details
            .FullRowSelect = True
            .GridLines = True
            .Columns.Add("Customer ID", 50)
            .Columns.Add("Name", 100)
            .Columns.Add("Address", 100)
            .Columns.Add("Existing Balance", 50)
            'FillListView(lvlist, GetData(sSql))
            .Columns.Add("Remaining Balance")
            For x As Integer = 1 To 5
                lvList.Items.Add(New ListViewItem(New String() {x.ToString, "Name" & x.ToString, "Address" & x.ToString, (x * 10).ToString, ""}))
            Next
        End With

        For Each lvi As ListViewItem In lvList.Items
            lvi.SubItems(4).Text = (CInt(lvi.SubItems(3).Text) + 1000).ToString
        Next

    End Sub
End Class

this the code of the program that i want to do, but i want the data will be loaded from the database, the columns: customerid,name,address and existing balance, and remaining balance will be computed in the looping

thanks.
 
Back
Top