C++: DataGridView::DataSource

简介: #pragma once#include "Form2.h"namespace cdemo { using namespace System; using namespace System::ComponentModel; using namespace System::Collections; using namespace System::Windows::Forms;
#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::Data;
	using namespace System::Drawing;

	/// <summary>
	/// Form1 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class Form1 : public System::Windows::Forms::Form
	{
	public:
		Form1(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~Form1()
		{
			if (components)
			{
				delete components;
			}
		}
	private: System::Windows::Forms::Label^  label1;
	private: System::Windows::Forms::DataGridView^  dataGridView1;
	protected: 

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->label1 = (gcnew System::Windows::Forms::Label());
			this->dataGridView1 = (gcnew System::Windows::Forms::DataGridView());
			(cli::safe_cast<System::ComponentModel::ISupportInitialize^  >(this->dataGridView1))->BeginInit();
			this->SuspendLayout();
			// 
			// label1
			// 
			this->label1->AutoSize = true;
			this->label1->Location = System::Drawing::Point(487, 21);
			this->label1->Name = L"label1";
			this->label1->Size = System::Drawing::Size(41, 12);
			this->label1->TabIndex = 0;
			this->label1->Text = L"label1";
			// 
			// dataGridView1
			// 
			this->dataGridView1->AllowUserToAddRows = false;
			this->dataGridView1->ColumnHeadersHeightSizeMode = System::Windows::Forms::DataGridViewColumnHeadersHeightSizeMode::AutoSize;
			this->dataGridView1->Location = System::Drawing::Point(32, 84);
			this->dataGridView1->Name = L"dataGridView1";
			this->dataGridView1->RowTemplate->Height = 23;
			this->dataGridView1->Size = System::Drawing::Size(478, 344);
			this->dataGridView1->TabIndex = 1;
			this->dataGridView1->CellDoubleClick += gcnew System::Windows::Forms::DataGridViewCellEventHandler(this, &Form1::dataGridView1_CellDoubleClick);
			// 
			// Form1
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::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 endregion
	private: System::Void Form1_Load(System::Object^  sender, System::EventArgs^  e) {

				 int i,pr=0;
				 for(i=1;i<=10;i++)				 
					 pr=pr*i;
                    
				 //char s="pr=%d";

				 this->label1->Text= pr.ToString();

				             //设置dataGridView的一些属性
            dataGridView1->Dock=DockStyle::Fill; 
            dataGridView1->AutoResizeColumns();
            dataGridView1->AutoSizeColumnsMode=DataGridViewAutoSizeColumnsMode::AllCells;
            dataGridView1->EnableHeadersVisualStyles=true;/*根据应用程序来设置的,如果为false则根据自己的设置来绘制*/

            //设置表头的属性
            DataGridViewCellStyle^ headerStyle=gcnew DataGridViewCellStyle;
            headerStyle->Font=gcnew System::Drawing::Font("Times New Roman",12,FontStyle::Bold);
            headerStyle->BackColor=Color::AliceBlue;
            headerStyle->ForeColor=Color::BurlyWood;
            dataGridView1->ColumnHeadersDefaultCellStyle=headerStyle;

            dataGridView1->AutoResizeColumnHeadersHeight();

				DataSet^ myDataSet = gcnew DataSet("Game Data");
				myDataSet->Tables->Add("Player");
				myDataSet->Tables->Add("Score");
 
				DataTable^ playerTable = myDataSet->Tables["Player"];
				DataColumn^ firstNameColumn1 = playerTable->Columns->Add("First Name",String::typeid);
				DataColumn^ lastNameColumn1 = playerTable->Columns->Add("Last Name",String::typeid);
				playerTable->Columns->Add("Email", String::typeid);
				playerTable->Rows->Add("geovin","du","geovindu@163.com");
				playerTable->Rows->Add("聚文","涂","geovindu@qq.com");
                 //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::Forms::DataGridViewCellEventArgs^  e) {

             Form2 ^ frm2 = gcnew Form2();
			 frm2->Text="编辑资料";
			 frm2->textBox1->Text=dataGridView1->Rows[e->RowIndex]->Cells["First Name"]->Value->ToString();
			 frm2->textBox2->Text=dataGridView1->Rows[e->RowIndex]->Cells["Email"]->Value->ToString();
             frm2->Show();
             //this->Hide();
                
                 
                
			 }
	};
}
#pragma once

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


namespace cdemo {

	/// <summary>
	/// Form2 摘要
	///
	/// 警告: 如果更改此类的名称,则需要更改
	///          与此类所依赖的所有 .resx 文件关联的托管资源编译器工具的
	///          “资源文件名”属性。否则,
	///          设计器将不能与此窗体的关联
	///          本地化资源正确交互。
	/// </summary>
	public ref class Form2 : public System::Windows::Forms::Form
	{
	public:
		Form2(void)
		{
			InitializeComponent();
			//
			//TODO: 在此处添加构造函数代码
			//
		}

	protected:
		/// <summary>
		/// 清理所有正在使用的资源。
		/// </summary>
		~Form2()
		{
			if (components)
			{
				delete components;
			}
		}
	public: System::Windows::Forms::TextBox^  textBox1;
	protected: 
	public: System::Windows::Forms::TextBox^  textBox2;

	private:
		/// <summary>
		/// 必需的设计器变量。
		/// </summary>
		System::ComponentModel::Container ^components;

#pragma region Windows Form Designer generated code
		/// <summary>
		/// 设计器支持所需的方法 - 不要
		/// 使用代码编辑器修改此方法的内容。
		/// </summary>
		void InitializeComponent(void)
		{
			this->textBox1 = (gcnew System::Windows::Forms::TextBox());
			this->textBox2 = (gcnew System::Windows::Forms::TextBox());
			this->SuspendLayout();
			// 
			// textBox1
			// 
			this->textBox1->Location = System::Drawing::Point(183, 50);
			this->textBox1->Name = L"textBox1";
			this->textBox1->Size = System::Drawing::Size(100, 21);
			this->textBox1->TabIndex = 0;
			// 
			// textBox2
			// 
			this->textBox2->Location = System::Drawing::Point(183, 102);
			this->textBox2->Name = L"textBox2";
			this->textBox2->Size = System::Drawing::Size(100, 21);
			this->textBox2->TabIndex = 1;
			// 
			// Form2
			// 
			this->AutoScaleDimensions = System::Drawing::SizeF(6, 12);
			this->AutoScaleMode = System::Windows::Forms::AutoScaleMode::Font;
			this->ClientSize = System::Drawing::Size(542, 440);
			this->Controls->Add(this->textBox2);
			this->Controls->Add(this->textBox1);
			this->Name = L"Form2";
			this->Text = L"Form2";
			this->Load += gcnew System::EventHandler(this, &Form2::Form2_Load);
			this->ResumeLayout(false);
			this->PerformLayout();

		}
#pragma endregion
	private: System::Void Form2_Load(System::Object^  sender, System::EventArgs^  e) {


			 }
	};
}


目录
相关文章
|
8月前
|
监控 安全 Cloud Native
海外泼天流量丨浅谈全球化技术架构
全球化是对技术架构的终极挑战,面临的不仅仅是技术的问题,而是包含了经济、文化等多因素差异的用户关系问题。积极借助遍布全球的云计算基础设施和云原生的架构设计原则,将能更加高效的构建高可用的全球化技术架构,支持全球业务的持续增长。
412 122
|
5月前
|
存储 人工智能 安全
阿里云双项入选首批智算一体化权威评估 以AI Stack加速政企智能化升级 ——万卡智算集群服务推进方阵(ICCPA)第三期沙龙在京举办
2024年4月9日,中国信通院主办的智算集群服务沙龙第三期在京召开。阿里云凭借领先的AI技术能力,成为首批通过《面向大模型的智算一体化解决方案》评估的云厂商,并入选行业应用案例。会上,阿里云AI Stack赋能政企大模型高效落地,提供软硬一体推理优化框架,支持主流开源模型快速适配,助力企业构建高性能私有化AI服务,已在政务、金融等领域广泛应用。
321 6
|
7月前
|
人工智能 自然语言处理 搜索推荐
【上篇】-分两篇步骤介绍-如何用topview生成和自定义数字人-关于AI的使用和应用-如何生成数字人-优雅草卓伊凡-如何生成AI数字人
【上篇】-分两篇步骤介绍-如何用topview生成和自定义数字人-关于AI的使用和应用-如何生成数字人-优雅草卓伊凡-如何生成AI数字人
360 24
【上篇】-分两篇步骤介绍-如何用topview生成和自定义数字人-关于AI的使用和应用-如何生成数字人-优雅草卓伊凡-如何生成AI数字人
|
6月前
|
SQL Unix API
夏令时的坑:你的数据库真的能正确处理时间跳变吗?
时区是地球上使用相同标准时间的区域。由于地球的自转,为了保证各地的时间与当地的日出日落相协调,全球划分为多个时区。
243 0
|
8月前
|
人工智能 搜索推荐 Serverless
AI 剧本生成与动画创作方案评测
《AI剧本生成与动画创作》解决方案评测:该方案利用阿里云技术,实现从剧本撰写到视频合成的一站式自动化流程,部署文档指引准确,逻辑清晰。内容创作上显著简化流程、降低门槛,适合短视频创作者等用户,但部分术语较晦涩,特定风格的动画创作个性化不足。建议增加模板和教程,优化服务初始化流程,进一步提升用户体验。
274 15
|
存储 监控 安全
ZABBIX监控vcenter集群
ZABBIX监控vcenter集群
ZABBIX监控vcenter集群
|
Android开发 异构计算 移动开发
大比拼 | 下一代高性能跨平台UI渲染引擎
本文通过阐述跨平台 UI 渲染引擎的历史,并且实际研究探索构建下一代跨平台 UI 渲染引擎。
8630 0
|
Linux 网络安全 网络虚拟化
VPN网关使用场景有哪些?
VPN网关是一款基于Internet的网络连接服务,通过加密通道的方式实现企业数据中心、企业办公网络或Internet终端与阿里云专有网络(VPC)安全可靠的连接。VPN网关配置灵活,可满足不同的应用场景。
1691 0
|
关系型数据库 定位技术 PostgreSQL