-3
#pragma once

namespace StudentDataSearch {

    using namespace System;
    using namespace System::ComponentModel;
    using namespace System::Collections;
    using namespace System::Windows::Forms;
    using namespace System::Data;
    using namespace System::Drawing;

    /// <summary>
    /// Summary for Form1
    /// </summary>
    public ref class Form1 : public System::Windows::Forms::Form
    {
    public:
        Form1(void)
        {
            InitializeComponent();
            //
            //TODO: Add the constructor code here
            //
        }

    protected:
        /// <summary>
        /// Clean up any resources being used.
        /// </summary>
        ~Form1()
        {
            if (components)
            {
                delete components;
            }
        }
    private: System::Windows::Forms::Button^  btnSearch;
    protected: 

    protected: 

    private: System::Windows::Forms::Label^  Course_ID1;
    protected: 

    private: System::Windows::Forms::TextBox^  txtTargetID;

    private: System::Windows::Forms::GroupBox^  groupBox1;
    private: System::Windows::Forms::TextBox^  txtSeats;
    private: System::Windows::Forms::Label^  Seats;
    private: System::Windows::Forms::TextBox^  txtID;
    private: System::Windows::Forms::Label^  Course_ID;
    private: System::Windows::Forms::TextBox^  txtName;
    private: System::Windows::Forms::Label^  Course_Names2;
    private: System::Windows::Forms::Button^  btnSearchName;


    private:
        /// <summary>
        /// Required designer variable.
        /// </summary>
        System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
        /// <summary>
        /// Required method for Designer support - do not modify
        /// the contents of this method with the code editor.
        /// </summary>
        void InitializeComponent(void)
        {
            this->btnSearch = (gcnew System::Windows::Forms::Button());
            this->Course_ID1 = (gcnew System::Windows::Forms::Label());
            this->txtTargetID = (gcnew System::Windows::Forms::TextBox());
            this->groupBox1 = (gcnew System::Windows::Forms::GroupBox());
            this->txtSeats = (gcnew System::Windows::Forms::TextBox());
            this->Seats = (gcnew System::Windows::Forms::Label());
            this->txtID = (gcnew System::Windows::Forms::TextBox());
            this->Course_ID = (gcnew System::Windows::Forms::Label());
            this->txtName = (gcnew System::Windows::Forms::TextBox());
            this->Course_Names2 = (gcnew System::Windows::Forms::Label());
            this->btnSearchName = (gcnew System::Windows::Forms::Button());
            this->groupBox1->SuspendLayout();
            this->SuspendLayout();
            // 
            // btnSearch
            // 
            this->btnSearch->Location = System::Drawing::Point(12, 12);
            this->btnSearch->Name = L"btnSearch";
            this->btnSearch->Size = System::Drawing::Size(144, 39);
            this->btnSearch->TabIndex = 0;
            this->btnSearch->Text = L"Search by Course ID";
            this->btnSearch->UseVisualStyleBackColor = true;
            this->btnSearch->Click += gcnew System::EventHandler(this, &Form1::btnSearch_Click);
            // 
            // Course_ID1
            // 
            this->Course_ID1->AutoSize = true;
            this->Course_ID1->Location = System::Drawing::Point(317, 28);
            this->Course_ID1->Name = L"Course_ID1";
            this->Course_ID1->Size = System::Drawing::Size(54, 13);
            this->Course_ID1->TabIndex = 1;
            this->Course_ID1->Text = L"Course ID";
            // 
            // txtTargetID
            // 
            this->txtTargetID->Location = System::Drawing::Point(377, 25);
            this->txtTargetID->Name = L"txtTargetID";
            this->txtTargetID->Size = System::Drawing::Size(100, 20);
            this->txtTargetID->TabIndex = 2;
            // 
            // groupBox1
            // 
            this->groupBox1->Controls->Add(this->txtSeats);
            this->groupBox1->Controls->Add(this->Seats);
            this->groupBox1->Controls->Add(this->txtID);
            this->groupBox1->Controls->Add(this->Course_ID);
            this->groupBox1->Controls->Add(this->txtName);
            this->groupBox1->Controls->Add(this->Course_Names2);
            this->groupBox1->Location = System::Drawing::Point(12, 145);
            this->groupBox1->Name = L"groupBox1";
            this->groupBox1->Size = System::Drawing::Size(465, 140);
            this->groupBox1->TabIndex = 3;
            this->groupBox1->TabStop = false;
            this->groupBox1->Text = L"Search Results";
            // 
            // txtSeats
            // 
            this->txtSeats->Location = System::Drawing::Point(301, 81);
            this->txtSeats->Name = L"txtSeats";
            this->txtSeats->Size = System::Drawing::Size(100, 20);
            this->txtSeats->TabIndex = 5;
            // 
            // Seats
            // 
            this->Seats->AutoSize = true;
            this->Seats->Location = System::Drawing::Point(298, 65);
            this->Seats->Name = L"Seats";
            this->Seats->Size = System::Drawing::Size(34, 13);
            this->Seats->TabIndex = 4;
            this->Seats->Text = L"Seats";
            // 
            // txtID
            // 
            this->txtID->Location = System::Drawing::Point(204, 81);
            this->txtID->Name = L"txtID";
            this->txtID->Size = System::Drawing::Size(91, 20);
            this->txtID->TabIndex = 3;
            // 
            // Course_ID
            // 
            this->Course_ID->AutoSize = true;
            this->Course_ID->Location = System::Drawing::Point(206, 65);
            this->Course_ID->Name = L"Course_ID";
            this->Course_ID->Size = System::Drawing::Size(54, 13);
            this->Course_ID->TabIndex = 2;
            this->Course_ID->Text = L"Course ID";
            // 
            // txtName
            // 
            this->txtName->Location = System::Drawing::Point(25, 81);
            this->txtName->Name = L"txtName";
            this->txtName->Size = System::Drawing::Size(173, 20);
            this->txtName->TabIndex = 1;
            // 
            // Course_Names2
            // 
            this->Course_Names2->AutoSize = true;
            this->Course_Names2->Location = System::Drawing::Point(22, 65);
            this->Course_Names2->Name = L"Course_Names2";
            this->Course_Names2->Size = System::Drawing::Size(71, 13);
            this->Course_Names2->TabIndex = 0;
            this->Course_Names2->Text = L"Course Name";
            // 
            // btnSearchName
            // 
            this->btnSearchName->Location = System::Drawing::Point(12, 57);
            this->btnSearchName->Name = L"btnSearchName";
            this->btnSearchName->Size = System::Drawing::Size(144, 39);
            this->btnSearchName->TabIndex = 4;
            this->btnSearchName->Text = L"Search by Course Name";
            this->btnSearchName->UseVisualStyleBackColor = true;
            // 
            // Form1
            // 
            this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
            this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
            this->ClientSize = System::Drawing::Size(519, 297);
            this->Controls->Add(this->btnSearchName);
            this->Controls->Add(this->groupBox1);
            this->Controls->Add(this->txtTargetID);
            this->Controls->Add(this->Course_ID1);
            this->Controls->Add(this->btnSearch);
            this->Name = L"Form1";
            this->Text = L"Student Data Search";
            this->Load += gcnew System::EventHandler(this, &Form1::Form1_Load);
            this->groupBox1->ResumeLayout(false);
            this->groupBox1->PerformLayout();
            this->ResumeLayout(false);
            this->PerformLayout();

        }
#pragma endregion
        private: array<String^>^ CourseArr;
        private: array<String^>^ CourseID;
        private: array<Int32>^ SeatsArr;
        private: String^ strTarget;
        private: String^ strOut;

    private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {
                 // Course Names
                 CourseArr = gcnew array<String^>(9);
                 CourseArr->SetValue("Computer Sci 1511", 0);
                 CourseArr->SetValue("Computer Sci 1521", 1);
                 CourseArr->SetValue("Composition 1120", 2);
                 CourseArr->SetValue("Math 1296", 3);
                 CourseArr->SetValue("Physics 1120", 4);
                 CourseArr->SetValue("Biology 1100", 5);
                 CourseArr->SetValue("Chemistry 1100", 6);
                 CourseArr->SetValue("Anthropology 1210", 7);
                 CourseArr->SetValue("Economics 1000", 8);


                 // Course ID
                 CourseID = gcnew array<String^>(9);
                 CourseID->SetValue("123", 0);
                 CourseID->SetValue("124", 1);
                 CourseID->SetValue("135", 2);
                 CourseID->SetValue("145", 3);
                 CourseID->SetValue("146", 4);
                 CourseID->SetValue("149", 5);
                 CourseID->SetValue("155", 6);
                 CourseID->SetValue("162", 7);
                 CourseID->SetValue("175", 8);


                 //Seats Avaliable
                 SeatsArr = gcnew array<Int32>(9);
                 SeatsArr->SetValue(0, 0);
                 SeatsArr->SetValue(25, 1);
                 SeatsArr->SetValue(14, 2);
                 SeatsArr->SetValue(5, 3);
                 SeatsArr->SetValue(0, 4);
                 SeatsArr->SetValue(20, 5);
                 SeatsArr->SetValue(17, 6);
                 SeatsArr->SetValue(0, 7);
                 SeatsArr->SetValue(12, 8);


             }




private: System::Void btnSearch_Click(System::Object^  sender, System::EventArgs^  e) {
             int course, small, large;
             int id;
             int seats;
             small = 0;
             large = 9;
             strTarget = txtTargetID->Text;

             if (strTarget == "")
             {
                 MessageBox::Show("Fill in empty fields");
                 return;
            }
help needed here ----------------------------------------------------------

我需要遍历我的数组并使用它们的值(上面列出)并将选定的值放入某些文本框中,但我不确定是否需要另一个 for 循环或请提供帮助,感谢所有帮助。

             for (int small = 0; small <= large; small++)
             {
                 for (int course = 0; course < CourseID->Length; course++)
                 {
                 txtName->Text = CourseArr[0];
                 txtID->Text = CourseID[0];
                 txtSeats->Text = SeatsArr[0].ToString();
                 }
            }
4

1 回答 1

2

在循环中引用CourseArr[0]etc. 每次都会为您提供相同的元素。

你需要参考CourseArr[course]

(我怀疑这不足以解决您的问题,但很难弄清楚这需要什么!)

于 2013-06-04T17:35:01.467 回答