?
Solved

Possible array solution

Posted on 2005-05-04
1
Medium Priority
?
142 Views
Last Modified: 2010-04-23
I have a form which has three textboxes (txtAircraftID,txtCarrierName, and txtFuelCharges). and a listbox lstAircraftId. What I need to have happen is once the user fills the textboxes and the menu is clicked the AircraftID appears in the listbox, once the text boxes are cleared and the aircraftID is highlighted in the listbox the aircraftID and the other entered text reappears in the proper textbox. I can get the aircraftID to appear in the textbox, and I can get the AircraftID to reappear in it's textbox but not the other entered text. I was hoping someone could help me with an array to accomplish this. Here is the code for the menu and the listbox.

  Private Sub mmuRecordSaveArrival_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles mmuRecordSaveArrival.Click
        Dim newitemtext As String = txtAircraftID.Text

Private Sub AircraftID_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles lstAircraftID.SelectedIndexChanged
        Dim sAircraftID As String = lstAircraftID.SelectedItem.ToString()
        txtAircraftID.Text = lstAircraftID.SelectedItem.ToString

I think an array is the solution but I don't know exactly how to code it.
0
Comment
Question by:augie0216
1 Comment
 
LVL 19

Accepted Solution

by:
arif_eqbal earned 1500 total points
ID: 13933061
OK here's a possible solution
Its the full form code, just copy paste in a new Form and run.

I have used HashTable instead of Array, it is easier to fill back the TextBoxes that way once they are emptied.

The form has a button Add, when you click it the values are added into the hashTable and the ID into the ListBox also the TextBoxes are cleared. Then when you select an ID from the ListBox all tthe values are again filled in the TextBoxes from the HashTable.


Public Class FrmArray
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents TxtID As System.Windows.Forms.TextBox
    Friend WithEvents TxtName As System.Windows.Forms.TextBox
    Friend WithEvents TxtFuelCharges As System.Windows.Forms.TextBox
    Friend WithEvents LstIDs As System.Windows.Forms.ListBox
    Friend WithEvents CmdAdd As System.Windows.Forms.Button
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.TxtID = New System.Windows.Forms.TextBox
        Me.TxtName = New System.Windows.Forms.TextBox
        Me.TxtFuelCharges = New System.Windows.Forms.TextBox
        Me.LstIDs = New System.Windows.Forms.ListBox
        Me.CmdAdd = New System.Windows.Forms.Button
        Me.SuspendLayout()
        '
        'TxtID
        '
        Me.TxtID.Location = New System.Drawing.Point(184, 32)
        Me.TxtID.Name = "TxtID"
        Me.TxtID.Size = New System.Drawing.Size(112, 20)
        Me.TxtID.TabIndex = 0
        Me.TxtID.Text = ""
        '
        'TxtName
        '
        Me.TxtName.Location = New System.Drawing.Point(184, 56)
        Me.TxtName.Name = "TxtName"
        Me.TxtName.Size = New System.Drawing.Size(112, 20)
        Me.TxtName.TabIndex = 1
        Me.TxtName.Text = ""
        '
        'TxtFuelCharges
        '
        Me.TxtFuelCharges.Location = New System.Drawing.Point(184, 80)
        Me.TxtFuelCharges.Name = "TxtFuelCharges"
        Me.TxtFuelCharges.Size = New System.Drawing.Size(112, 20)
        Me.TxtFuelCharges.TabIndex = 2
        Me.TxtFuelCharges.Text = ""
        '
        'LstIDs
        '
        Me.LstIDs.Location = New System.Drawing.Point(16, 32)
        Me.LstIDs.Name = "LstIDs"
        Me.LstIDs.Size = New System.Drawing.Size(112, 69)
        Me.LstIDs.TabIndex = 3
        '
        'CmdAdd
        '
        Me.CmdAdd.Location = New System.Drawing.Point(200, 112)
        Me.CmdAdd.Name = "CmdAdd"
        Me.CmdAdd.Size = New System.Drawing.Size(72, 24)
        Me.CmdAdd.TabIndex = 4
        Me.CmdAdd.Text = "Add"
        '
        'FrmArray
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(344, 273)
        Me.Controls.Add(Me.CmdAdd)
        Me.Controls.Add(Me.LstIDs)
        Me.Controls.Add(Me.TxtFuelCharges)
        Me.Controls.Add(Me.TxtName)
        Me.Controls.Add(Me.TxtID)
        Me.Name = "FrmArray"
        Me.Text = "FrmArray"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private Structure Aircraft
        Dim ID As String
        Dim Name As String
        Dim FuelCharges As Integer
    End Structure

    Dim AircraftDetails As New Hashtable

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

    End Sub

    Private Sub CmdAdd_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles CmdAdd.Click
        LstIDs.Items.Add(TxtID.Text)
        Dim AircraftDetail As Aircraft
        AircraftDetail.ID = TxtID.Text
        AircraftDetail.Name = TxtName.Text
        AircraftDetail.FuelCharges = CType(TxtFuelCharges.Text, Integer)
        AircraftDetails.Add(AircraftDetail.ID, AircraftDetail)
        ClearTextBoxes()
    End Sub

    Private Sub ClearTextBoxes()
        TxtID.Clear()
        TxtName.Clear()
        TxtFuelCharges.Clear()
    End Sub

    Private Sub LstIDs_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles LstIDs.SelectedIndexChanged
        Dim AircraftDetail As Aircraft
        AircraftDetail = AircraftDetails.Item(LstIDs.SelectedItem)
        TxtID.Text = AircraftDetail.ID
        TxtName.Text = AircraftDetail.Name
        TxtFuelCharges.Text = AircraftDetail.FuelCharges.ToString
    End Sub
End Class
0

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Introduction As chip makers focus on adding processor cores over increasing clock speed, developers need to utilize the features of modern CPUs.  One of the ways we can do this is by implementing parallel algorithms in our software.   One recent…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
This video shows how to quickly and easily deploy an email signature for all users in Office 365 and prevent it from being added to replies and forwards. (the resulting signature is applied on the server level in Exchange Online) The email signat…
Despite its rising prevalence in the business world, "the cloud" is still misunderstood. Some companies still believe common misconceptions about lack of security in cloud solutions and many misuses of cloud storage options still occur every day. …
Suggested Courses
Course of the Month14 days, 22 hours left to enroll

840 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question