gmahler5th
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
http://www.stevetout.com/list.gif
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
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
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
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
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 :-)
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 :-)
Your answer is in here...
https://www.experts-exchange.com/questions/21197963/Student-needs-help-with-sample-app-in-VB-net.html
https://www.experts-exchange.com/questions/21197963/Student-needs-help-with-sample-app-in-VB-net.html
ASKER
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
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(Paymen t) 'Balance
.Items(iCounter).SubItems. Add(Paymen t) '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
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"
.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.
.Items(iCounter).SubItems.
.Items(iCounter).SubItems.
.Items(iCounter).SubItems.
End With
iCounter += 1 'Column counter
Next
End Sub
ASKER
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
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER