#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. [Java集合] 彻底搞懂HashMap,HashTable,ConcurrentHashMap之关联.

    注: 今天看到的一篇讲hashMap,hashTable,concurrentHashMap很透彻的一篇文章, 感谢原作者的分享. 原文地址: http://blog.csdn.net/zhanger ...

  2. MSSQL Server数据库的四种连接方法和sql连接字符串

    MSSQL Server数据库的四种连接方法和sql连接字符串 分类: [ 03 ] C#(131) [ 07 ] SQL Server(68) [ 01 ] .NET(189) 今天用SQL Ser ...

  3. vm中centos7配置静态ip访问外网

    我使用的是桥接方式,具体步骤如下   1.设置虚拟机网络: 编辑>虚拟网络编辑器   2.设置vm中操作系统的网络设置   3.进入centos7中后修改网络配置:     另附我的宿主机网络配 ...

  4. Python基础语法

    学习一门编程语言,通常是学习该语言的以下几个部分的内容: 基础语法:如,变量的声明与调用.基本输出语句.代码块语法.注释等: 数据类型:通常都为 数字.字符串.布尔值.数组.链表.Map.Set等: ...

  5. css text-align-last设置末尾文本对齐方式

    text-align-last:auto | start | end | left | right | center | justify auto: 无特殊对齐方式. left: 内容左对齐. cen ...

  6. 面向对象tab栏例子分析

    <!DOCTYPE html> <html lang="en"> <head> <meta charset="UTF-8&quo ...

  7. SSIS连接SAPBI

        SSIS默认的连接管理器是没有连接到Oracle或SAPBI的,因此如果希望SSIS调用SAP RFC的话,可以使用微软提供的连接管理器插件.     有关这一点的详细信息可以参考MSDN的官 ...

  8. 深入理解CSS伪类

    × 目录 [1]锚点 [2]UI元素 [3]结构伪类[4]其他 前面的话 伪类经常与伪元素混淆,伪元素的效果类似于通过添加一个实际的元素才能达到,而伪类的效果类似于通过添加一个实际的类来达到.实际上c ...

  9. javase基础复习攻略《四》

    本篇内容重点介绍JAVA中的异常处理机制,什么是JAVA异常?JAVA异常是JAVA提供的用于处理程序中错误的一种机制.所谓错误就是指在程序的运行过程中出现的一些异常事件(如:0溢出,数组下表越界,所 ...

  10. MongoDB的学习--索引

    索引可以用来优化查询,而且在某些特定类型的查询中,索引是必不可少的.为集合选择合适的索引是提高性能的关键. 先来mock数据 for (i = 0; i < 1000000; i++) { db ...