Link to home
Start Free TrialLog in
Avatar of gmahler5th
gmahler5thFlag for United States of America

asked on

Display data values in a list

Could somebody please post some sample code (not an entire application) for how I can display a list of values, as depicted in this picture?

http://www.stevetout.com/list.gif
Avatar of gmahler5th
gmahler5th
Flag of United States of America image

ASKER

Oh, by the way, the data in the list is based on the loan balance and interest paid for each payment over the term of the loan.
hey again!

this site here : http://support.microsoft.com/default.aspx?scid=kb;en-us;Q316303 shows how to do it basically

popultae an array and bind the array to a datagrid.

I dont have Visual Studio on me, but ill be home in about 1 1/2 hours to help if your still stuck!

Dave
Avatar of arif_eqbal
arif_eqbal

I hope you can buld the upper half shown in the image
You need to put some textBoxes etc.

the lower part is a DataGrid, drag and drop a DataGrid on your form, and name it DetailsDataGrid, Then you would probably like to display details in it on the Click of the button "Display Details" as shown in the gif.
So put this declaration at Form Level

Dim DTDetails as dataTable

Now modify and put this code on the Button Click

        DTDetails = New DataTable
'Change your table name here
        Dim DA As OleDbDataAdapter = New OleDbDataAdapter("Select * From Mytable", ConStr)
        DA.Fill(DTDetails)

DetailsDataGrid.DataSource = DTDetails


Got home about 15 mins ago, need to go out (getting hastled by the missus)

Its nearly there, except it puts all 0's/.. not 100% sure why, but im really sorry i cant finish it for you.

If you are still having problem, im sure someone will spot a simple stupid mistake of mine. Sorry..

Create a new class with this

Public Class repayment
    Private lmonth As Long
    Private dBalance As Double
    Private dInstall As Double
    Private dInterest As Double
    Private dPrincipal As Double

    Public Sub New(ByVal lMonth As Long, ByVal dBalance As Double, ByVal dInstall As Double, ByVal dInterest As Double, ByVal dPrincipal As Double)
        lMonth = Month
        dBalance = Balance
        dInstall = Installment
        dInterest = Interest
        dPrincipal = Principal
    End Sub

    Public Property Month() As Long
        Get
            Return lmonth
        End Get
        Set(ByVal Value As Long)
            lmonth = Value
        End Set
    End Property

    Public Property Balance() As Double
        Get
            Return dBalance
        End Get
        Set(ByVal Value As Double)
            dBalance = Value
        End Set
    End Property

    Public Property Installment() As Double
        Get
            Return dInstall
        End Get
        Set(ByVal Value As Double)
            dInstall = Value
        End Set
    End Property

    Public Property Interest() As Double
        Get
            Return dInterest
        End Get
        Set(ByVal Value As Double)
            dInterest = Value
        End Set
    End Property

    Public Property Principal() As Double
        Get
            Return dPrincipal
        End Get
        Set(ByVal Value As Double)
            dPrincipal = Value
        End Set
    End Property
End Class

'***************************************************************
'***************************************************************
'***************************************************************
'***************************************************************

then in the main form use this

  Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        'values from your form
        Dim homeValue As Double = 250000
        Dim downPayment As Double = 50000
        Dim interest As Double = 7
        Dim loanDuration = 30
        Dim monthlyInstallment As Double = 1330.605

        'the good stuff
        Dim al As New ArrayList

        Dim i As Long
        Dim balanceLeft As Double = homeValue - downPayment
        Dim interestPaid As Double
        For i = 1 To loanDuration * 12
            interestPaid = balanceLeft * interest / 100 / 12
            balanceLeft = balanceLeft + interestPaid - monthlyInstallment
            al.Add(New repayment(i, balanceLeft, monthlyInstallment, interestPaid, interestPaid - monthlyInstallment))
        Next

        Me.DataGrid1.DataSource = al
    End Sub


'************************


Dave :-)
Planocz, can you copy and paste the code that is relevant to just creating the list?  Your code is way to long for me to be able to identify what I am looking for.

The variables I am using are:

    'declare your variables here
    Dim PVal, APR, FVal, Payment, TotPmts, dblMonth, dblRateMonth As Double
    Dim Fmt As String

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click

        'assign the values from textboxes to the variables
        PVal = txtPrincipal.Text
        APR = txtRate.Text
        If APR > 1 Then APR = APR / 100 ' Ensure proper form.
        TotPmts = txtYears.Text
        dblMonth = TotPmts * 12
        dblRateMonth = APR / 12
I just thru this together for a quick demo...

the numbers(answers) are not right, but you just wanted to see how to use the Listview box.

   Private Sub InitializeListview()
        Cursor.Current = Cursors.WaitCursor
        With ListView1
            .Columns.Add("Month", 50, HorizontalAlignment.Center)
            .Columns.Add("Balance", 70, HorizontalAlignment.Right)
            .Columns.Add("Installment", 80, HorizontalAlignment.Right)
            .Columns.Add("Interest Paid", 80, HorizontalAlignment.Right)
            .Columns.Add("Principal Paid", 80, HorizontalAlignment.Right)
            .View = View.Details
        End With
        Cursor.Current = Cursors.Default

        'These are just default values that you can start with
        txtPrincipal.Text = "250,000"       'Cost of Item
        txtRate.Text = "7"                      'Interest Rate
        txtYears.Text = "30"                   'Years to pay

    End Sub
    'declare your variables here
    Dim PVal, APR, FVal, Payment, TotPmts, dblMonth, dblRateMonth, Interest As Double

    Private Sub btnCalculate_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles btnCalculate.Click
        Dim iCount As Short
        Dim iCounter As Short = 0
        Dim Fmt As String

        Fmt = "###,###,##0.00"          ' Define money format.

        'assign the values from textboxes to the variables
        PVal = txtPrincipal.Text
        APR = txtRate.Text
        If APR > 1 Then APR = APR / 100         ' Ensure proper form.
        TotPmts = txtYears.Text * 12
        dblMonth = TotPmts * 12
        dblRateMonth = APR / 12

        Interest = Payment - PVal
        Interest = (Int((Interest + 0.005) * 100) / 100)           ' Round interest.

        For iCount = 1 To TotPmts                                 'Number of months to pay loan
            With ListView1
                .Items.Add(UCase(iCount))                                           'Month
                .Items(iCounter).SubItems.Add(Payment)                      'Balance
                .Items(iCounter).SubItems.Add(Payment)                      'Payment (Installment)
                .Items(iCounter).SubItems.Add(Format(Interest, Fmt))   'Interest      
                .Items(iCounter).SubItems.Add(Format(PVal, Fmt))        'Principal
            End With
            iCounter += 1             'Column counter
        Next
    End Sub
I tried using this code, but I don't see where the list should appear?  How do I change my form to accomodate displaying the list?
ASKER CERTIFIED SOLUTION
Avatar of Howard Cantrell
Howard Cantrell
Flag of United States of America image

Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial
SOLUTION
Link to home
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Start Free Trial