#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) { }
};
}

  visual studio 2005,2008,2010

http://www.codeproject.com/Tips/810596/Csharp-VB-NET-Cplusplus-CLI-Create-read-and-write

C++: DataGridView::DataSource的更多相关文章

  1. DataGridView.DataSource= list(Of T)

    注:本文样例的代码承接上篇文章:DataTable填充实体类返回泛型集合. 在D层查询完毕之后.我们将DataTable转化为泛型集合.然后经过中间各层,返回U层.到了这里,问题来了.我们这时候要将这 ...

  2. 解决DataGridView.DataSource重复赋值而不显示问题

    List<Person> list=new List<Person>(); ;i<;i++) { list.Add(new Person(){........}) } d ...

  3. DataGridView DataSource INotifyPropertyChanged 避免闪烁的方法

    代码说话: dgvPosition就是需要避免闪烁的DataGridView 主要是加2段代码 1.SetStyle 2.datagridview设置DoubleBuffered属性为True pub ...

  4. C# Winfrom DataGridView DataSource绑定数据源后--解决排序问题

    帮助类: public class SortBindingHelper<T> : BindingList<T> { private bool isSortedCore = tr ...

  5. DataGridView DataSource 如何实现排序

    将数据绑定在下面的类中就可以实现排序 public class SortableBindingList<T> : BindingList<T> { private ArrayL ...

  6. [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict

    一  需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...

  7. [Winform] DataGridView 总结(FAQ)

    Q1.  如何使单元格不可编辑? A:设置 ReadOnly 属性,可以设置的对象包括 DataGridViewRow(行).DataGridViewColumn(列).DataGridViewCel ...

  8. 设置DataSource后DateGridView不显示的问题

    在一个WinForm小程序中,有两处需要用DataGridView控件显示数据.设置DataGridView.DataSource为数据查询结果后,第一个DataGridView可以正常显示数据,而第 ...

  9. C# DataGridView控件清空数据完美解决方法

    C# DataGridView控件绑定数据后清空数据在清除DataGridview的数据时: 1.DataSource为NULL(DataGridView.DataSource= null;)这样会将 ...

随机推荐

  1. JS的脚本语言

    js的脚本语言全程javascript在网页里面使用的脚本语言:分类:1.嵌入网页里面2.在外部脚本标签可以写在网页的任何地方,但一般都写在网页的底部:<script type="te ...

  2. 关于js中的同步和异步

    最近看到前端面试问到js中的同步和异步,这个问题该怎么回答? 梳理一下,js对于异步的处理,很多人的第一反应是ajax,这只能说是对了一半. 1.个人觉得,js中,最基础的异步是setTimeout和 ...

  3. android rectF

    new Rect(left , top, right , bottom) 这个构造方法需要四个参数这四个参数 指明了什么位置 ?我们就来解释怎么画 这个 矩形 这四个 参数 分别代表的意思是:left ...

  4. poj1949Chores(建图或者dp)

    /* 题意:n个任务,有某些任务要在一些任务之前完成才能开始做! 第k个任务的约束只能是1...k-1个任务!问最终需要最少的时间完成全部的 任务! 思路:第i个任务要在第j个任务之前做,就在i,j之 ...

  5. 后端码农谈前端(CSS篇)第三课:选择器

    一.选择器 1.ID选择器: 语法:首先,ID 选择器前面有一个 # 号 - 也称为棋盘号或井号.请看下面的规则: *#intro {font-weight:bold;} 与类选择器一样,ID 选择器 ...

  6. bootstrap-table 分页的问题

    文档网站 http://wenzhixin.net.cn/p/bootstrap-table/docs/examples.html#via-javascript-table 问题1 :服务器端取不到f ...

  7. CentOS 7 关闭防火墙和SELinux

    [修改机器名] # vi /etc/hostname [关SELinux] # vi /etc/selinux/config设置SELINUX=disabled [关防火墙] # systemctl ...

  8. Spark入门实战系列--2.Spark编译与部署(下)--Spark编译安装

    [注]该系列文章以及使用到安装包/测试数据 可以在<倾情大奉送--Spark入门实战系列>获取 .编译Spark .时间不一样,SBT是白天编译,Maven是深夜进行的,获取依赖包速度不同 ...

  9. HTML5在移动端开发的12大特性

    1.离线缓存为HTML5开发移动应用提供了基础 HTML5 Web Storage API可以看做是加强版的cookie,不受数据大小限制,有更好的弹性以及架构,可以将数据写入到本机的ROM中,还可以 ...

  10. Android开发资源获取国内代理(转载)

    Android Dev Tools官网地址:www.androiddevtools.cn 收集整理Android开发所需的Android SDK.开发中用到的工具.Android开发教程.Androi ...