I want to clear the entire contents so that when a different selection is made on one of the checkboxes, only that data is displayed when the calculate button is depressed.

Thanks in advance!!

Here's my code:

Public Class LoanCalc


        Private Sub butCalc_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butCalc.Click
            'This procedure executes when the user clicks the Calculate
            'button to produce a loan payment based on the requirements
            'as stated in the service request.

            'Variable Declarations
            Dim douPrincipal As Double = Me.txtPrincipal.Text
            Dim douInterest() As Double = {5.35, 5.5, 5.75}
            Dim decYears() As Decimal = {7, 15, 30}
            Dim douPayment As Double
            Dim douRemainingBalance As Double
            Dim douInterestPaid As Double
            Dim intNumberPayments As Integer
            Dim intPaymentNumber As Integer


            If Me.CheckBox1.Checked Then


                'set the initial balance to the principal amount
                douRemainingBalance = douPrincipal

                'Calculate the payment
                douPayment = ((douPrincipal * (douInterest(0) / 100) / 12) / (1 - Math.Pow(1 + (douInterest(0) / 100) / 12, -(decYears(0) * 12))))
                intNumberPayments = decYears(0) * 12
                'calculate payment, principal, accruedInterest, remainingbalance
                For intPaymentNumber = 1 To intNumberPayments

                    'Calculates the interest paid with each payment and the remaining balance            
                    douInterestPaid = douRemainingBalance * (douInterest(0) / 100 / 12) 'interest paid for current month is the (remaining balance)*(the monthly interest rate... i.e. the interest rate, as a dec., divided by 12)
                    douRemainingBalance = douRemainingBalance - (douPayment - douInterestPaid) ' subtract the princial payment portion of the monthly payment amount from the remaining balance

                    'Append data to the dataGridView 
                    DataGridView1.Rows.Add(intPaymentNumber, FormatCurrency(douPayment, 2), FormatCurrency(douPrincipal, 2), FormatCurrency(douInterestPaid, 2), FormatCurrency(douRemainingBalance, 2))

                Next

            ElseIf Me.CheckBox2.Checked Then

                'set the initial balance to the principal amount
                douRemainingBalance = douPrincipal

                'Calculate the payment
                douPayment = ((douPrincipal * (douInterest(1) / 100) / 12) / (1 - Math.Pow(1 + (douInterest(1) / 100) / 12, -(decYears(1) * 12))))
                intNumberPayments = decYears(1) * 12
                'calculate payment, principal, accruedInterest, remainingbalance
                For intPaymentNumber = 1 To intNumberPayments

                    'Calculates the interest paid with each payment and the remaining balance            
                    douInterestPaid = douRemainingBalance * (douInterest(1) / 100 / 12) 'interest paid for current month is the (remaining balance)*(the monthly interest rate... i.e. the interest rate, as a dec., divided by 12)
                    douRemainingBalance = douRemainingBalance - (douPayment - douInterestPaid) ' subtract the princial payment portion of the monthly payment amount from the remaining balance

                    'Append data to the dataGridView 
                    DataGridView1.Rows.Add(intPaymentNumber, FormatCurrency(douPayment, 2), FormatCurrency(douPrincipal, 2), FormatCurrency(douInterestPaid, 2), FormatCurrency(douRemainingBalance, 2))

                Next
            ElseIf Me.CheckBox3.Checked Then
                'set the initial balance to the principal amount
                douRemainingBalance = douPrincipal

                'Calculate the payment
                douPayment = ((douPrincipal * (douInterest(2) / 100) / 12) / (1 - Math.Pow(1 + (douInterest(2) / 100) / 12, -(decYears(2) * 12))))
                intNumberPayments = decYears(2) * 12
                'calculate payment, principal, accruedInterest, remainingbalance
                For intPaymentNumber = 1 To intNumberPayments

                    'Calculates the interest paid with each payment and the remaining balance            
                    douInterestPaid = douRemainingBalance * (douInterest(2) / 100 / 12) 'interest paid for current month is the (remaining balance)*(the monthly interest rate... i.e. the interest rate, as a dec., divided by 12)
                    douRemainingBalance = douRemainingBalance - (douPayment - douInterestPaid) ' subtract the princial payment portion of the monthly payment amount from the remaining balance

                    'Append data to the dataGridView 
                    DataGridView1.Rows.Add(intPaymentNumber, FormatCurrency(douPayment, 2), FormatCurrency(douPrincipal, 2), FormatCurrency(douInterestPaid, 2), FormatCurrency(douRemainingBalance, 2))

                Next
            End If
        End Sub

        Private Sub butEXIT_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles butEXIT.Click
            'This procedure exits the program when the user clicks the EXIT button
            Me.Close()
        End Sub
End Class

Edited 3 Years Ago by Reverend Jim: Fixed formatting

ISSUE RESOLVED, PLEASE DISREGARD...

This is what I used.

'clear the grid so the information is not appended to the end of each selection
DataGridView1.Rows.Clear()

This article has been dead for over six months. Start a new discussion instead.