Welcome to Dream.In.Code
Become a VB.NET Expert!

Join 149,412 VB.NET Programmers for FREE! Get instant access to thousands of VB.NET experts, tutorials, code snippets, and more! There are 2,229 people online right now. Registration is fast and FREE... Join Now!




Populating Combobox using Arrays

 
Reply to this topicStart new topic

Populating Combobox using Arrays

Rhivka
21 Jan, 2008 - 11:30 PM
Post #1

New D.I.C Head
*

Joined: 19 Nov, 2007
Posts: 2


My Contributions
I've been working on this program for my VB.NET class and everything is working fine except for populating the combobox with the array. The problem is in initialized the array, I think. But when I change that, it says it's wrong. If someone could please take a look and see if you can spot where I'm messing up, I'd really appreciate it!

CODE

' Declare Variables
    Dim arrayInterestTerm(2, 2) As Array   ' Instantiate interest term array
    Dim dblLoanAmount As Double             ' Variable for Loan Amount
    Dim dblInterestRate As Double           ' Variable for Interest Rate
    Dim intTerm As Integer                  ' Variable for Loan Term
    Dim intTermResult As Integer
    Dim dblInterestResult As Double
    Dim decMonthlyPayment As Decimal        ' Variable for Monthly Payment

    Private Sub SunniVBMortgageCalculator2_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        ' Loads combobox with interest and term array values
        Me.ClientSize = New System.Drawing.Size(250, 230) ' Set application window size
        Me.txtLoanAmount.Text = ""      ' Resets Loan Amount Text Box to Empty String
        Me.txtLoanAmount.Focus()        ' Sets focus to Loan Amount Text Box

        Me.dgv.Hide() ' Hide Data Grid View

        Try
            Me.buildInterestTermArray()         'populate interest term array
        Catch ex As Exception
            MessageBox.Show("Error building interest option list, please exit and re-open the application.")
        End Try

        Try
            For x As Integer = 0 To Me.arrayInterestTerm.GetUpperBound(x)     'add array to comboBox excluding price information
                Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(x, 0))
            Next x
        Catch ex As Exception                   'if loop fails, clear list and add items manually
            Me.comboInterestTerm.Items.Clear()
            Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(0, 0))
            Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(1, 0))
            Me.comboInterestTerm.Items.Add(Me.arrayInterestTerm(2, 0))
        End Try

        Me.comboInterestTerm.Text = Me.comboInterestTerm.Items.Item(0)  'set default selected item to item 0
        Me.txtLoanAmount.Focus()

    End Sub
    Private Sub buildInterestTermArray()
        ' Builds room choice arrays
        Me.arrayInterestTerm.SetValue("7", 0, 0)
        Me.arrayInterestTerm.SetValue("years @", 0, 1)
        Me.arrayInterestTerm.SetValue("5.35", 0, 2)
        Me.arrayInterestTerm.SetValue("15", 1, 0)
        Me.arrayInterestTerm.SetValue("years @", 1, 1)
        Me.arrayInterestTerm.SetValue("5.50", 1, 2)
        Me.arrayInterestTerm.SetValue("30", 2, 0)
        Me.arrayInterestTerm.SetValue("years @", 2, 1)
        Me.arrayInterestTerm.SetValue("5.75", 2, 2)
    End Sub


You may be asking, why include the "years @" in the array for the combobox? Well I want the combobox to look like "7 years @ 5.35" etc when it is populated. But I need to use the "7" and "5.35" in calculations. Is there a better way to do this? I've been searching the web all night and haven't found a solution. I don't like to ask for help on message boards, but I feel I'm out of options. Thanks in advance for your time.
User is offlineProfile CardPM
+Quote Post

Nayana
RE: Populating Combobox Using Arrays
22 Jan, 2008 - 07:06 PM
Post #2

DIC Hawk - 나야나 नयन:
Group Icon

Joined: 14 Nov, 2007
Posts: 824



Thanked: 5 times
Dream Kudos: 175
My Contributions
I'm not sure exactly what you're trying to do. Could you include a sample list of values for the array, and what you would like to have in the ComboBox.

Then it would be easier to help you.
User is offlineProfile CardPM
+Quote Post

Fast ReplyReply to this topicStart new topic
Time is now: 1/7/09 10:49AM

Be Social

Dream.In.Code RSS Feed Dream.In.Code LinkedIn Group Follow Us On Twitter

Live VB.NET Help!

VB.NET Tutorials

Reference Sheets

VB.NET Snippets

DIC Chatroom

Bye Bye Ads

Monthly Drawing

Thumb Drive

Top Contributors

Top 10 Kudos This Month