473,382 Members | 1,359 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,382 software developers and data experts.

How to use a List Box as a selector for data to show in another txtbox

I am relatively new to the C++ world - I am working on a form control that is supposed to use a List box to pull a value out of an array of values and display it in a text box.

This is way above my head, but I want to figure it out.

Here is my task:

1-Write a program for Eddies Equipment Rental
2-Build a windows form that looks like this:


3-Eddie Charges one amount for full day rentals and another amout for half days.
4-Use 3 parallel arrays to store the data
Data is as follows:


5-Load the list box during the form load (optional)
6-The user should click on the item in the list box to select the equipment GOT THIS
7-the user must enter an f or h for full or half day GOT THIS

8-the Display Charge button will display the approrpiate amount in the rental charge text box I really need help with this.

the Clear button will clear the 2 text boxes GOT THIS

I have the form built - and the clear button working.

I have the listbox issueing values based on selection - but don't know how to put that data in to an array that is also getting data from the Duration Text box. I actually am not sure how to get the data outside the function itself. To use it with the click function of the Dsiplay Button.

I got the txtDuration to validate input - and it uses a message box to alert the user if they input the wrong thing. Though the built in error handler is a bit annoyoing - if you hit the backspace the program throws another error message box - that I didn't program, would like to turn that off. it tells you that you must have exactly one character - which is not necresary.


Alot of the problem I am having is that I don't know where to put stuff - when there is already a ton of code generated that I don't understand.

Any help would be greatly appreciated.

code for form that I have already is below:
Expand|Select|Wrap|Line Numbers
  1. #pragma once
  2.  
  3. namespace Final {
  4.  
  5.     using namespace System;
  6.     using namespace System::ComponentModel;
  7.     using namespace System::Collections;
  8.     using namespace System::Windows::Forms;
  9.     using namespace System::Data;
  10.     using namespace System::Drawing;
  11.  
  12.     /// <summary>
  13.     /// Summary for Form1
  14.     /// </summary>
  15.     public ref class Form1 : public System::Windows::Forms::Form
  16.     {
  17.     public:
  18.         Form1(void)
  19.         {
  20.             InitializeComponent();
  21.             //
  22.             //TODO: Add the constructor code here
  23.             //
  24.         }
  25.  
  26.     protected:
  27.         /// <summary>
  28.         /// Clean up any resources being used.
  29.         /// </summary>
  30.         ~Form1()
  31.         {
  32.             if (components)
  33.             {
  34.                 delete components;
  35.             }
  36.         }
  37.     private: System::Windows::Forms::ListBox^  lstEquipment;
  38.     protected: 
  39.     private: System::Windows::Forms::Label^  lblDuration;
  40.     private: System::Windows::Forms::TextBox^  txtDuration;
  41.     private: System::Windows::Forms::Label^  lblCharge;
  42.     private: System::Windows::Forms::TextBox^  txtCharge;
  43.     private: System::Windows::Forms::Button^  btnDisplay;
  44.     private: System::Windows::Forms::Button^  btnClear;
  45.     private: System::Windows::Forms::Label^  lblInstruction;
  46.  
  47.     private:
  48.         /// <summary>
  49.         /// Required designer variable.
  50.         /// </summary>
  51.         System::ComponentModel::Container ^components;
  52.  
  53. #pragma region Windows Form Designer generated code
  54.         /// <summary>
  55.         /// Required method for Designer support - do not modify
  56.         /// the contents of this method with the code editor.
  57.         /// </summary>
  58.         void InitializeComponent(void)
  59.         {
  60.             this->lstEquipment = (gcnew System::Windows::Forms::ListBox());
  61.             this->lblDuration = (gcnew System::Windows::Forms::Label());
  62.             this->txtDuration = (gcnew System::Windows::Forms::TextBox());
  63.             this->lblCharge = (gcnew System::Windows::Forms::Label());
  64.             this->txtCharge = (gcnew System::Windows::Forms::TextBox());
  65.             this->btnDisplay = (gcnew System::Windows::Forms::Button());
  66.             this->btnClear = (gcnew System::Windows::Forms::Button());
  67.             this->lblInstruction = (gcnew System::Windows::Forms::Label());
  68.             this->SuspendLayout();
  69.             // 
  70.             // lstEquipment
  71.             // 
  72.             this->lstEquipment->FormattingEnabled = true;
  73.             this->lstEquipment->Items->AddRange(gcnew cli::array< System::Object^  >(3) {L"1- Rug Cleaner", L"2- Lawn Mower", L"3- Paint Sprayer"});
  74.             this->lstEquipment->Location = System::Drawing::Point(95, 46);
  75.             this->lstEquipment->Name = L"lstEquipment";
  76.             this->lstEquipment->Size = System::Drawing::Size(158, 56);
  77.             this->lstEquipment->TabIndex = 1;
  78.             this->lstEquipment->SelectedIndexChanged += gcnew System::EventHandler(this, &Form1::Item_Selected);
  79.             // 
  80.             // lblDuration
  81.             // 
  82.             this->lblDuration->AutoSize = true;
  83.             this->lblDuration->Location = System::Drawing::Point(92, 154);
  84.             this->lblDuration->Name = L"lblDuration";
  85.             this->lblDuration->Size = System::Drawing::Size(130, 13);
  86.             this->lblDuration->TabIndex = 2;
  87.             this->lblDuration->Text = L"Select a Duration (F or H):";
  88.             // 
  89.             // txtDuration
  90.             // 
  91.             this->txtDuration->Location = System::Drawing::Point(228, 150);
  92.             this->txtDuration->Name = L"txtDuration";
  93.             this->txtDuration->Size = System::Drawing::Size(34, 20);
  94.             this->txtDuration->TabIndex = 3;
  95.             this->txtDuration->TextChanged += gcnew System::EventHandler(this, &Form1::Input_Duration);
  96.             // 
  97.             // lblCharge
  98.             // 
  99.             this->lblCharge->AutoSize = true;
  100.             this->lblCharge->Location = System::Drawing::Point(92, 179);
  101.             this->lblCharge->Name = L"lblCharge";
  102.             this->lblCharge->Size = System::Drawing::Size(78, 13);
  103.             this->lblCharge->TabIndex = 4;
  104.             this->lblCharge->Text = L"Rental Charge:";
  105.             // 
  106.             // txtCharge
  107.             // 
  108.             this->txtCharge->Location = System::Drawing::Point(176, 176);
  109.             this->txtCharge->Name = L"txtCharge";
  110.             this->txtCharge->Size = System::Drawing::Size(86, 20);
  111.             this->txtCharge->TabIndex = 5;
  112.             // 
  113.             // btnDisplay
  114.             // 
  115.             this->btnDisplay->Location = System::Drawing::Point(74, 217);
  116.             this->btnDisplay->Name = L"btnDisplay";
  117.             this->btnDisplay->Size = System::Drawing::Size(75, 23);
  118.             this->btnDisplay->TabIndex = 6;
  119.             this->btnDisplay->Text = L"Display Charge";
  120.             this->btnDisplay->UseVisualStyleBackColor = true;
  121.             this->btnDisplay->Click += gcnew System::EventHandler(this, &Form1::Display_Charge);
  122.             // 
  123.             // btnClear
  124.             // 
  125.             this->btnClear->Location = System::Drawing::Point(221, 217);
  126.             this->btnClear->Name = L"btnClear";
  127.             this->btnClear->Size = System::Drawing::Size(75, 23);
  128.             this->btnClear->TabIndex = 7;
  129.             this->btnClear->Text = L"Clear";
  130.             this->btnClear->UseVisualStyleBackColor = true;
  131.             this->btnClear->Click += gcnew System::EventHandler(this, &Form1::ClearInput);
  132.             // 
  133.             // lblInstruction
  134.             // 
  135.             this->lblInstruction->AutoSize = true;
  136.             this->lblInstruction->Location = System::Drawing::Point(105, 30);
  137.             this->lblInstruction->Name = L"lblInstruction";
  138.             this->lblInstruction->Size = System::Drawing::Size(124, 13);
  139.             this->lblInstruction->TabIndex = 8;
  140.             this->lblInstruction->Text = L"Click on the Item to Rent";
  141.             // 
  142.             // Form1
  143.             // 
  144.             this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
  145.             this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
  146.             this->ClientSize = System::Drawing::Size(359, 264);
  147.             this->Controls->Add(this->lblInstruction);
  148.             this->Controls->Add(this->btnClear);
  149.             this->Controls->Add(this->btnDisplay);
  150.             this->Controls->Add(this->txtCharge);
  151.             this->Controls->Add(this->lblCharge);
  152.             this->Controls->Add(this->txtDuration);
  153.             this->Controls->Add(this->lblDuration);
  154.             this->Controls->Add(this->lstEquipment);
  155.             this->Name = L"Form1";
  156.             this->Text = L"Eddies Equipment Rental";
  157.             this->ResumeLayout(false);
  158.             this->PerformLayout();
  159.  
  160.         }
  161. #pragma endregion
  162.     private: System::Void ClearInput(System::Object^  sender, System::EventArgs^  e) 
  163.              {
  164.                  txtDuration->Clear();
  165.                  txtCharge->Clear();
  166.  
  167.              }
  168. private: System::Void Item_Selected(System::Object^  sender, System::EventArgs^  e) 
  169.          {
  170.              int Item;
  171.              if(lstEquipment->SelectedIndex==0)
  172.                  Item=1;
  173.              else if(lstEquipment->SelectedIndex==1)
  174.                 Item=2;
  175.              else
  176.                 Item=3;
  177.          }
  178. private: System::Void Input_Duration(System::Object^  sender, System::EventArgs^  e) 
  179.          {
  180.              int Duration;
  181.              wchar_t convertDuration;
  182.              convertDuration = System::Convert::ToChar(txtDuration->Text);
  183.              if(txtDuration->Text=="F" || txtDuration->Text=="f")
  184.                  Duration=1;
  185.              else if(txtDuration->Text=="H" || txtDuration->Text=="h")
  186.                  Duration=2;
  187.              else
  188.                  MessageBox::Show("Your Entry Must be 'F' for Full Day or 'H' for Half Day","Input Error", MessageBoxButtons::OKCancel,MessageBoxIcon::Asterisk);
  189.  
  190.  
  191.          }
  192. private: System::Void Display_Charge(System::Object^  sender, System::EventArgs^  e) 
  193.          {
  194.  
  195.          }
  196. };
  197. }
  198.  
  199.  
  200.  
Dec 11 '11 #1
0 1502

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

Similar topics

3
by: Baby Blue | last post by:
I have 2 codes below to grap data from another site. I use them to get the data from one News site. However, when I click on some link inside (such as :...
2
by: ramesh | last post by:
hi, I am using Com+ in my application. It will have InsertRecords,selectRecords,updateRecords function. In the Web Form i have Drop-down list. I want to select records from SQL and add it to this...
0
by: mel_apiso | last post by:
Hi, after uncatalog one database, and catalog again with other name, if I try to connect with this database, everything is ok, but list applications only show me the connection with the...
6
by: psbasha | last post by:
Hi, I am assigning the list/dict values to another list/dict variable as shown below. List : List1 = List2 = List1
7
by: Boki | last post by:
Hi All, I can't pass data to another form: in form2: private void button1_Click(object sender, EventArgs e) { Form1 form_copy = new Form1();
10
by: Debajit Adhikary | last post by:
I have two lists: a = b = What I'd like to do is append all of the elements of b at the end of a, so that a looks like: a =
3
by: agarwalsunitadhn | last post by:
hello i am working in C#.net. I want to know how to close one form and show another one. I had done the following code this.Hide(); MainForm frm = new...
7
by: limperger | last post by:
Hello everyone! Just in case anyone has any wonder about this... I have a parameter query that searchs for records that have the particular word provided by the user in a memo field (using the...
0
by: tvnaidu | last post by:
gdb list command - doesnot show source - where I should copy source ? # gdb /pfrm2.0/bin/cacd Could not find platform independent libraries <prefix> Could not find platform dependent libraries...
0
by: napstar | last post by:
I would like to know how to customize a list library to show only the user's documents. do sharepoint lists have an event analogous to ASP.NET Page Load event?
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...

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.