#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;
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^ button1;
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->button1 = (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";
//
// button1
//
this->button1->Location = System::Drawing::Point(12, 57);
this->button1->Name = L"button1";
this->button1->Size = System::Drawing::Size(144, 39);
this->button1->TabIndex = 4;
this->button1->Text = L"Search by Course Name";
this->button1->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->button1);
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: 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->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) {
ここのエラー --------------------------------------------------
情報を収集するためにいくつかの配列を設定しました。これまでのところ、3 つの配列に値を設定し、for ループを設定して配列を実行し、テキスト ボックスのコース ID に入力された内容に基づいて目的の情報を選択しましたが、何も印刷せず、配列を変数に割り当ててから、変数をテキストボックスに入れることでうまくいくと思った理由がわかりません。助けていただければ幸いです
int course;
int id;
int seats;
for (int i = 0; i < course; i++)
{
txtName->Text = CourseArr[i]->ToString();
txtID->Text =CourseID[i]->ToString();
txtSeats->Text = SeatsArr[i]->ToString();
course = CourseArr[i]->ToString();
id = CourseID[i]->ToString();
seats = SeatsArr[i]->ToString();
}
}
};
}