#pragma once#include "Form2.h" namespace CDemo {using namespace system;using namespace system::componentmodel;using Namespace system::collections;using namespace system::windows::forms;using namespace System::D ata;using namespace System::D rawing;///<summary>///Form1 Summary//////Warning: If you change the name of this class, you need to change/////For the managed Resource compiler tool associated with all. resx files that this class depends on. The resource file Name property. Otherwise,///The designer will not be able to interact correctly with this form's association//localization resource. </summary>public ref class Form1:public System::windows::forms::form{public:form1 (void) { InitializeComponent ();////todo: Add the constructor code here//}protected:///<summary>///clean up all the resources in use. </summary>~form1 () {if (components) {delete components;}} private:system::windows::forms::label^ label1;private:system::windows::forms::D atagridview^ dataGridView1; protected:private:///<summary>///the required designer variables. </summary>system::componentmodel::container ^components; #pragma region Windows Form Designer generated code/ <summary>///Designer supports the required method-do not///use generationThe Code Editor modifies the contents of this method. </summary>void InitializeComponent (void) {This->label1 = (gcnew System::windows::forms::label ()); this- >datagridview1 = (gcnew system::windows::forms::D atagridview ());(cli::safe_cast<system::componentmodel::i supportinitialize^ > (this->datagridview1))->begininit (); This->suspendlayout ();///label1//this-> Label1->autosize = True;this->label1->location = System::D rawing::P oint (487); this->label1->name = L "Label1"; this->label1->size = System::D rawing::size (.), This->label1->tabindex = 0;this-> Label1->text = L "Label1";///datagridview1//this->datagridview1->allowusertoaddrows = false;this-> Datagridview1->columnheadersheightsizemode = system::windows::forms::D atagridviewcolumnheadersheightsizemode: : autosize;this->datagridview1->location = System::D rawing::P oint (+), This->datagridview1->name = L " DataGridView1 "; this->datagridview1->rowtemplate->height = 23;this->daTagridview1->size = System::D rawing::size (478, 344); This->datagridview1->tabindex = 1;this-> Datagridview1->celldoubleclick + = gcnew system::windows::forms::D atagridviewcelleventhandler (This, &Form1:: Datagridview1_celldoubleclick)////form1//this->autoscaledimensions = System::D Rawing::sizef (6, N);this-> AutoScaleMode = System::windows::forms::autoscalemode::font;this->clientsize = System::D rawing::size (586, 485); This->controls->add (This->datagridview1); This->controls->add (this->label1); this->Name = L " Form1 "; this->text = L" Form1 "; This->load + = Gcnew System::EventHandler (this, &form1::form1_load);(Cli::safe _cast<system::componentmodel::isupportinitialize^ > (this->datagridview1)->endinit ();this-> ResumeLayout (false); This->performlayout ();} #pragma endregionprivate:system::void Form1_Load (system::object^ sender, system::eventargs^ e) {int i,pr=0; for (i=1;i& lt;=10;i++) Pr=pr*i; Char s="pr=%d"; This->label1->text= PR. ToString (); Set some properties of DataGridView datagridview1->dock=dockstyle::fill; Datagridview1->autoresizecolumns (); datagridview1->autosizecolumnsmode=datagridviewautosizecolumnsmode::allcells; datagridview1->enableheadersvisualstyles=true;/* is set according to the application and, if False, draws///sets the properties of the header according to its own settings datagr idviewcellstyle^ headerstyle=gcnew DataGridViewCellStyle; Headerstyle->font=gcnew System::D Rawing::font ("Times New Roman", 12,fontstyle::bold); headerstyle->backcolor=color::aliceblue; headerstyle->forecolor=color::burlywood; datagridview1->columnheadersdefaultcellstyle=headerstyle; Datagridview1->autoresizecolumnheadersheight ();D ataset^ myDataSet = gcnew DataSet ("Game Data");mydataset-> Tables->add ("Player"); Mydataset->tables->add ("Score"); datatable^ playertable = mydataset->tables["Player"];D Atacolumn^ firstNameColumn1 = Playertable->columns->add ("First Name", String::typeid);D atacolumn^ lastNameColumn1 = Playertable->columns->add ("Last Name", String::typeid);p layertable->columns->add ("Email", String:: typeID);p layertable->rows->add ("Geovin", "Du", "[email protected]");p layertable->rows->add ("Poly" , "Tu", "[email protected]"); 1.//datagridview1->datasource=mydataset->tables["Player"];//PLAYERTABLE;//2. Datagridview1->datasource=playertable;datagridview1->refresh ();//datagridview1->databindings::get; }////private:system::void Datagridview1_celldoubleclick (system::object^ sender, System::windows::f Orms::D atagridviewcelleventargs^ e) {Form2 ^ Frm2 = gcnew Form2 (); Frm2->show (); This->hide (); }};}
C + +: DataGridView::D Atasource