DataGrid pada Visual Studio

hasil output:

codingan my from:

#pragma once
namespace DataGridPopulate{
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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
    MyForm(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::DataGridView^  dataGridView1;
protected:
private: System::Windows::Forms::DataGridViewTextBoxColumn^  no;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  nama;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  npm;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  kelas;
private: System::Windows::Forms::ComboBox^  comboBox1;

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->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
        this->no = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->nama = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->npm = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->kelas = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
        this->SuspendLayout();
        // 
        // dataGridView1
        // 
        this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
        this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(4) {
            this->no, this->nama,
                this->npm, this->kelas
        });
        this->dataGridView1->Location = System::Drawing::Point(12, 58);
        this->dataGridView1->Name = L"dataGridView1";
        this->dataGridView1->Size = System::Drawing::Size(333, 191);
        this->dataGridView1->TabIndex = 0;
        // 
        // no
        // 
        this->no->HeaderText = L"No";
        this->no->Name = L"no";
        this->no->ReadOnly = true;
        this->no->Width = 30;
        // 
        // nama
        // 
        this->nama->HeaderText = L"Nama";
        this->nama->Name = L"nama";
        this->nama->ReadOnly = true;
        this->nama->Width = 120;
        // 
        // npm
        // 
        this->npm->HeaderText = L"NPM";
        this->npm->Name = L"npm";
        this->npm->ReadOnly = true;
        this->npm->Width = 80;
        // 
        // kelas
        // 
        this->kelas->HeaderText = L"Kelas";
        this->kelas->Name = L"kelas";
        this->kelas->ReadOnly = true;
        this->kelas->Width = 60;
        // 
        // comboBox1
        // 
        this->comboBox1->FormattingEnabled = true;
        this->comboBox1->Location = System::Drawing::Point(16, 31);
        this->comboBox1->Name = L"comboBox1";
        this->comboBox1->Size = System::Drawing::Size(284, 21);
        this->comboBox1->TabIndex = 1;
        // 
        // MyForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(360, 276);
        this->Controls->Add(this->comboBox1);
        this->Controls->Add(this->dataGridView1);
        this->Name = L"MyForm";
        this->Text = L"MyForm";
        this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
        this->ResumeLayout(false);

    }
pragma endregion
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
             array<String^, 2>^ data;
             data = gcnew array<String^, 2>{{ "shahnaz", "15117620", "2KA06" },
             { "ayu", "11172345", "2KA06" },
             { "cici", "15117457", "2KA06" },
             { "egy", "15117890", "2KA06" }};
             for (int i = 0; i < 4; i++)
             {
                 dataGridView1->Rows->Add();
                 dataGridView1->Rows[i]->Cells[0]->Value = Convert::ToString(i + 1);
                 dataGridView1->Rows[i]->Cells[1]->Value = data[i, 0];
                 dataGridView1->Rows[i]->Cells[2]->Value = data[i, 1];
                 dataGridView1->Rows[i]->Cells[3]->Value = data[i, 2];
                 comboBox1->Items->Add(data[i, 0] + " | " + data[i, 1]);
             }
}
};

}

{

namespace DataGridPopulate {
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 MyForm
/// </summary>
public ref class MyForm : public System::Windows::Forms::Form
{
public:
    MyForm(void)
    {
        InitializeComponent();
        //
        //TODO: Add the constructor code here
        //
    }

protected:
    /// <summary>
    /// Clean up any resources being used.
    /// </summary>
    ~MyForm()
    {
        if (components)
        {
            delete components;
        }
    }
private: System::Windows::Forms::DataGridView^  dataGridView1;
protected:
private: System::Windows::Forms::DataGridViewTextBoxColumn^  no;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  nama;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  npm;
private: System::Windows::Forms::DataGridViewTextBoxColumn^  kelas;
private: System::Windows::Forms::ComboBox^  comboBox1;

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->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
        this->no = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->nama = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->npm = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->kelas = (gcnew System::Windows::Forms::DataGridViewTextBoxColumn());
        this->comboBox1 = (gcnew System::Windows::Forms::ComboBox());
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->BeginInit();
        this->SuspendLayout();
        // 
        // dataGridView1
        // 
        this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
        this->dataGridView1->Columns->AddRange(gcnew cli::array< System::Windows::Forms::DataGridViewColumn^  >(4) {
            this->no, this->nama,
                this->npm, this->kelas
        });
        this->dataGridView1->Location = System::Drawing::Point(12, 58);
        this->dataGridView1->Name = L"dataGridView1";
        this->dataGridView1->Size = System::Drawing::Size(333, 191);
        this->dataGridView1->TabIndex = 0;
        // 
        // no
        // 
        this->no->HeaderText = L"No";
        this->no->Name = L"no";
        this->no->ReadOnly = true;
        this->no->Width = 30;
        // 
        // nama
        // 
        this->nama->HeaderText = L"Nama";
        this->nama->Name = L"nama";
        this->nama->ReadOnly = true;
        this->nama->Width = 120;
        // 
        // npm
        // 
        this->npm->HeaderText = L"NPM";
        this->npm->Name = L"npm";
        this->npm->ReadOnly = true;
        this->npm->Width = 80;
        // 
        // kelas
        // 
        this->kelas->HeaderText = L"Kelas";
        this->kelas->Name = L"kelas";
        this->kelas->ReadOnly = true;
        this->kelas->Width = 60;
        // 
        // comboBox1
        // 
        this->comboBox1->FormattingEnabled = true;
        this->comboBox1->Location = System::Drawing::Point(16, 31);
        this->comboBox1->Name = L"comboBox1";
        this->comboBox1->Size = System::Drawing::Size(284, 21);
        this->comboBox1->TabIndex = 1;
        // 
        // MyForm
        // 
        this->AutoScaleDimensions = System::Drawing::SizeF(6, 13);
        this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
        this->ClientSize = System::Drawing::Size(360, 276);
        this->Controls->Add(this->comboBox1);
        this->Controls->Add(this->dataGridView1);
        this->Name = L"MyForm";
        this->Text = L"MyForm";
        this->Load += gcnew System::EventHandler(this, &MyForm::MyForm_Load);
        (cli::safe_cast<System::ComponentModel::ISupportInitialize^>(this->dataGridView1))->EndInit();
        this->ResumeLayout(false);

    }
pragma endregion
private: System::Void MyForm_Load(System::Object^  sender, System::EventArgs^  e) {
             array<String^, 2>^ data;
             data = gcnew array<String^, 2>{{ "shahnaz", "15117620", "2KA06" },
             { "ayu", "11172345", "2KA06" },
             { "cici", "15117457", "2KA06" },
             { "egy", "15117890", "2KA06" }};
             for (int i = 0; i < 4; i++)
             {
                 dataGridView1->Rows->Add();
                 dataGridView1->Rows[i]->Cells[0]->Value = Convert::ToString(i + 1);
                 dataGridView1->Rows[i]->Cells[1]->Value = data[i, 0];
                 dataGridView1->Rows[i]->Cells[2]->Value = data[i, 1];
                 dataGridView1->Rows[i]->Cells[3]->Value = data[i, 2];
                 comboBox1->Items->Add(data[i, 0] + " | " + data[i, 1]);
             }
}
};
}

codingan cpp:

include "MyForm.h"
using namespace DataGridPopulate;
using namespace System;
using namespace System::Windows::Forms;
int main()
{
Application::Run(gcnew MyForm());
Application::EnableVisualStyles();
Application::SetCompatibleTextRenderingDefault(false);
DataGridPopulate::MyForm form;
Application::Run(%form);
}



Leave a comment