473,320 Members | 1,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,320 software developers and data experts.

how do i combine two diffrent listbox's to one by entering a detail from each listbox

hi,

i have 4 list boxes that need to have one row from one list box added to the other, then taking from there list boxes and added to another list box together.


for instance

member of staff enters a vehicles details into car list box and truck details into truck list box etc then enters customers details into cust listbox, now they user wants to combine the car to the customer and display in another listbox removing the details from the other listboxs into a new listbox called hired.


I'm using windows Form and have a hire button than displays a combobox where id like the reg number of the cars in the car listbox and another combobox that displays the cust id of cust from the cust listbox..then another button called hire out that wants to send the details from the form to the hired listbox.

I also need to be able to return the customer to the cust box and the car to the car box

Expand|Select|Wrap|Line Numbers
  1. using System;
  2. using System.Collections.Generic;
  3. using System.ComponentModel;
  4. using System.Data;
  5. using System.Drawing;
  6. using System.Linq;
  7. using System.Text;
  8. using System.Windows.Forms;
  9.  
  10. namespace SD2coursework
  11. {
  12.     public partial class FrmHireCo : Form
  13.         /*
  14.          * This is the main form for the car hire system.
  15.          * It allows the adding to new cars to the system, and displaying them in the fleet list
  16.          * 
  17.          */
  18.     {
  19.         private Fleet myFleet = new Fleet();
  20.         private scndFleet myScndFleet = new scndFleet();
  21.         private thrdFleet myThrdFleet = new thrdFleet();
  22.         private custBox myCustBox = new custBox();
  23.  
  24.         //Fleet object used to store cars
  25.  
  26.         public FrmHireCo()
  27.         {
  28.             //Default constructor
  29.             InitializeComponent();
  30.         }
  31.  
  32.  
  33.         private void updateFleetList()
  34.         {   //Used to update the fleet displayed on the form
  35.             lstFleet.Items.Clear();
  36.             foreach (Car c in myFleet.fleet)
  37.             {
  38.                 string line = "Car: " + c.make +" " + c.model + " " + c.colour + " " + c.registrationNumber;
  39.                 lstFleet.Items.Add(line);
  40.  
  41.  
  42.           }
  43.         }
  44.  
  45.         private void updateScndFleetList()
  46.         {   //Used to update the fleet displayed on the form
  47.             scndFleet.Items.Clear();
  48.             foreach (MiniBus c in myScndFleet.scndfleet)
  49.             {
  50.                 string line = "MiniBus: " + c.make + " " + c.model + " " + c.colour + " " + c.registrationNumber + " " + c.numberOfSeats;
  51.                 scndFleet.Items.Add(line);
  52.             }
  53.         }
  54.  
  55.         private void updateThrdFleetList()
  56.         {   // Used to update the thrdFleet displayed on the form
  57.             thrdFleet.Items.Clear();
  58.             foreach (Truck c in myThrdFleet.thrdfleet)
  59.             {
  60.  
  61.                 string line = "Truck: " + c.make + " " + c.model + " " + c.colour + " " + c.registrationNumber + " " + c.grossWeight;
  62.                 thrdFleet.Items.Add(line);
  63.             }
  64.         }
  65.  
  66.         private void updateCustBoxList()
  67.         {// Used to update the custBox displayed on the form
  68.             custBox.Items.Clear();
  69.             foreach (Customer c in myCustBox.CustBox)
  70.             {
  71.  
  72.                 string line = " Customer " + c.foreName + " " + c.surname + " " + c.firstLineOfAddress + " " + c.county + " " + c.postCode + " " + c.custId;
  73.                 custBox.Items.Add(line);
  74.             }
  75.         }
  76.  
  77.  
  78.  
  79.         private void btnAddMiniBus_Click(object sender, EventArgs e)
  80.         {
  81.             //Add a new miniBus
  82.             FrmMiniBus mBusGui = new FrmMiniBus(); //Form used to add new MiniBus
  83.             mBusGui.ShowDialog();
  84.             MiniBus myMiniBus = mBusGui.miniBus;         //Get new mini bus from MiniBus form
  85.             myScndFleet.addTothescndFleet(myMiniBus);      //Add to scndfleet list
  86.             updateScndFleetList();              //Update Scndfleet list
  87.         }
  88.  
  89.  
  90.  
  91.         private void btnAddTruck_Click(object sender, EventArgs e)
  92.         {
  93.             FrmTruck mTruckGui = new FrmTruck();// Form used to add new Truck
  94.             mTruckGui.ShowDialog();
  95.             Truck myTruck = mTruckGui.truck;//Get new truck from Truck form
  96.             myThrdFleet.addTothethrdFleet(myTruck);//add to thrdFleet list
  97.             updateThrdFleetList(); //update thrdTruck list
  98.         }
  99.  
  100.         private void btnAddCust_Click(object sender, EventArgs e)
  101.         {
  102.             FrmCustomer mCustGui = new FrmCustomer();// Form used to add new customer
  103.             mCustGui.ShowDialog();
  104.             Customer myCust = mCustGui.customer;
  105.             myCustBox.addTothecustBox(myCust);
  106.             updateCustBoxList();
  107.         }
  108.         private void btnAddCar_Click(object sender, EventArgs e)
  109.         {
  110.             //Add a new car
  111.             FrmCar carGui = new FrmCar(); //Form used to add new car
  112.             carGui.ShowDialog();
  113.             Car myCar = carGui.car;         //Get new car from form
  114.             myFleet.addToFleet(myCar);      //Add to fleet list
  115.             updateFleetList();              //Uodate fleet list
  116.         }
  117.  
  118.         private void lstFleet_SelectedIndexChanged(object sender, EventArgs e)
  119.         {
  120.             /*
  121.              * This method is used to control the list box
  122.              * It is called when a row is selected by the user, it then displays frmCar
  123.              * with the car details
  124.              */
  125.             if (lstFleet.SelectedIndex > -1)
  126.             {
  127.                 int index = lstFleet.SelectedIndex;
  128.                 Car myCar = myFleet.fleet.ElementAt(index);
  129.                 FrmCar carGui = new FrmCar();
  130.                 carGui.car = myCar;
  131.                 carGui.ShowDialog();
  132.                 updateFleetList(); 
  133.             }
  134.           }
  135.  
  136.  
  137.         private void scndFleet_SelectedIndexChanged(object sender, EventArgs e)
  138.         {
  139.             /*
  140.              * This method is used to control the list box
  141.              * It is called when a row is selected by the user, it then displays FrmMiniBus
  142.              * with the minibus details
  143.              */
  144.             if (scndFleet.SelectedIndex > -1)
  145.             {
  146.                 int index = scndFleet.SelectedIndex;
  147.                 MiniBus mBus = myScndFleet.scndfleet.ElementAt(index);
  148.                 FrmMiniBus mBusGui = new FrmMiniBus();
  149.                 mBusGui.miniBus = mBus;
  150.                 mBusGui.ShowDialog();
  151.  
  152.                 updateScndFleetList();
  153.             }
  154.         }
  155.  
  156.         private void thrdFleet_SelectedIndexChanged(object sender, EventArgs e)
  157.         {
  158.             /*
  159.              * This method is used to control the list box
  160.              * It is called when a row is selected by the user, it then displays FrmTruck
  161.              * with the truck details
  162.              */
  163.             if (thrdFleet.SelectedIndex > -1)
  164.             {
  165.                 int index = thrdFleet.SelectedIndex;
  166.                 Truck mTruck = myThrdFleet.thrdfleet.ElementAt(index);
  167.                 FrmTruck mTruckGui = new FrmTruck();
  168.                 mTruckGui.truck = mTruck;
  169.                 mTruckGui.Show();
  170.  
  171.                 updateThrdFleetList();
  172.  
  173.             }
  174.         }
  175.  
  176.         private void custBox_SelectedIndexChanged(object sender, EventArgs e)
  177.         {
  178.             /*
  179.             * This method is used to control the list box
  180.             * It is called when a row is selected by the user, it then displays FrmCustomer
  181.             * with the customer details
  182.             */
  183.             if (custBox.SelectedIndex > -1)
  184.             {
  185.                 int index = custBox.SelectedIndex;
  186.                 Customer mCust = myCustBox.CustBox.ElementAt(index);
  187.                 FrmCustomer mCustGui = new FrmCustomer();
  188.                 mCustGui.customer = mCust;
  189.                 mCustGui.Show();
  190.  
  191.                 updateCustBoxList();
  192.  
  193.             }
  194.         }
  195.  
  196.         private void btnQuit_Click(object sender, EventArgs e)
  197.         {
  198.             this.Close();
  199.         }
  200.  
  201.         private void FrmHireCo_Load(object sender, EventArgs e)
  202.         {
  203.           //  MessageBox.Show( "Please enter vehicle type and details ");
  204.         }
  205.  
  206.         private void btnHire_Click(object sender, EventArgs e)
  207.         {
  208.             FrmHireToCust HireToGui = new FrmHireToCust();// Form used to add new customer
  209.             HireToGui.ShowDialog();
  210.  
  211.  
  212.             //find car details from List of cars
  213.             //assign hirer to that list
  214.         }
  215.  
  216.         private void btnReturn_Click(object sender, EventArgs e)
  217.         {
  218.             FrmReturn ReturnGui = new FrmReturn();// Form used to add new customer
  219.             ReturnGui.ShowDialog();
  220.         }
  221.  
  222.  
  223.  
  224.  
  225.  
  226.  
  227.  
  228.  
  229.  
  230.  
  231.  
  232.  
  233.  
  234.     }
  235. }
  236.  
  237.  
  238. //Form Hire to cust after hitting Hire from above
  239.  
  240.  
  241.       }
  242.  
  243.         public string hirer
  244.         {
  245.             get
  246.             {
  247.                 return theHirer;
  248.             }
  249.             set
  250.             {
  251.                 theHirer = value;
  252.             }
  253.         }
  254.  
  255.         public string Car
  256.         {
  257.             get
  258.             {
  259.                 return theCar;
  260.             }
  261.             set
  262.             {
  263.                 theCar = value;
  264.             }
  265.         }
  266.  
  267.  
  268.  //dont know this is me testing but its not
  269.         private void FrmHireToCust_FormClosed(object sender, FormClosedEventArgs e)
  270.         {
  271.             //if (txtCustIdToHire.Text != null)
  272.             //{
  273.             //    theHirer = txtCustIdToHire.Text;
  274.             //}
  275.  
  276.             //if (txtCustREgNoToHire.Text != null)
  277.             //{
  278.             //    theCar = txtCustREgNoToHire.Text;
  279.             //}
  280.         }
  281.  
  282.         private void btnHireToCust_Click(object sender, EventArgs e)
  283.         {
  284.             //Close the form. Causes FrmMiniBusClosed() to be called.
  285.             this.Close();
  286.         }
  287.  
  288.  
  289.  
  290.  
  291.  
  292.  
  293.  
  294.  
  295.         //dont know this is me testing but its not workingcomboBox1_SelectedIndexChanged(object sender, EventArgs e)
  296.         //{
  297.         //    custBox.Equals(CustId);
  298.         //}
  299.     }
  300. }
  301.  
  302.  
  303.  
Nov 17 '10 #1
0 1351

Sign in to post your reply or Sign up for a free account.

Similar topics

1
by: Annette Massie | last post by:
I would like to have a form that lists current addresses being used. On this form I would also like to have a command button that would allow the user to add an address if they do not see it...
5
by: RBohannon | last post by:
I have a multi-selectable listbox named lstTitles. In the OnClick event I had the following: If Not IsNull(Me.lstTitles) Then ' do something with list selection Else ' do something else End...
0
by: Spare Change | last post by:
Given for a ListBox this.HLinks.MouseDown += new System.Windows.Forms.MouseEventHandler (this.HLinks_MouseDown);// this.HLinks.SelectedIndexChanged += new...
3
by: Chris Kettenbach | last post by:
Hello all, Quick question. I have a listbox that is populated by items from a database. When the user select something from the list, I want to populate another listbox based on the selection in...
2
by: COHENMARVIN | last post by:
I've been doing a simple for-each loop to remove multiple selected items from one listbox, and to dump them in another listbox. for each item in LeftListBox.Items if (item.Selected = true) Then...
0
by: David J | last post by:
Hi, I am strugling with the propertygrid and a listbox. I am using the universaldropdowneditor from the codeproject (code below). However I am populating the listbox via a datasource. The problem...
1
by: The Confessor | last post by:
I currently have a listbox in my program which I populate with data from a random access file as follows: For T = 1 To HighestPointID FileGet(1, Point(T), T) ListBox_Point.Items.Add(T & " Lat:...
4
by: srichand | last post by:
Hi All, Can somebody help me out in adding a tooltip to a listbox using js....
0
by: LostInMd | last post by:
Hi All, I've got an owner drawn listBox where I draw and measure the items that I add to the listBox. For example, I have a listBox that can only display 10 characters on each horizontal line. ...
1
akashazad
by: akashazad | last post by:
Hi All Pl some body tell me is it possible to have a datagridView in which each column can have diff no of rows in it?
0
by: DolphinDB | last post by:
Tired of spending countless mintues downsampling your data? Look no further! In this article, you’ll learn how to efficiently downsample 6.48 billion high-frequency records to 61 million...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: Vimpel783 | last post by:
Hello! Guys, I found this code on the Internet, but I need to modify it a little. It works well, the problem is this: Data is sent from only one cell, in this case B5, but it is necessary that data...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
0
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.