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;
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的更多相关文章
- DataGridView.DataSource= list(Of T)
注:本文样例的代码承接上篇文章:DataTable填充实体类返回泛型集合. 在D层查询完毕之后.我们将DataTable转化为泛型集合.然后经过中间各层,返回U层.到了这里,问题来了.我们这时候要将这 ...
- 解决DataGridView.DataSource重复赋值而不显示问题
List<Person> list=new List<Person>(); ;i<;i++) { list.Add(new Person(){........}) } d ...
- DataGridView DataSource INotifyPropertyChanged 避免闪烁的方法
代码说话: dgvPosition就是需要避免闪烁的DataGridView 主要是加2段代码 1.SetStyle 2.datagridview设置DoubleBuffered属性为True pub ...
- C# Winfrom DataGridView DataSource绑定数据源后--解决排序问题
帮助类: public class SortBindingHelper<T> : BindingList<T> { private bool isSortedCore = tr ...
- DataGridView DataSource 如何实现排序
将数据绑定在下面的类中就可以实现排序 public class SortableBindingList<T> : BindingList<T> { private ArrayL ...
- [WinForm] DataGridView 绑定 DT && ComboBox 列绑定 Dict
一 需求介绍 一般像枚举类型的数据,我们在数据库里存储着诸如(1.2.3.4-)或者("001"."002"."003"-)此类,但是界面 ...
- [Winform] DataGridView 总结(FAQ)
Q1. 如何使单元格不可编辑? A:设置 ReadOnly 属性,可以设置的对象包括 DataGridViewRow(行).DataGridViewColumn(列).DataGridViewCel ...
- 设置DataSource后DateGridView不显示的问题
在一个WinForm小程序中,有两处需要用DataGridView控件显示数据.设置DataGridView.DataSource为数据查询结果后,第一个DataGridView可以正常显示数据,而第 ...
- C# DataGridView控件清空数据完美解决方法
C# DataGridView控件绑定数据后清空数据在清除DataGridview的数据时: 1.DataSource为NULL(DataGridView.DataSource= null;)这样会将 ...
随机推荐
- Java Socket Server的演进 (一)
最近在看一些网络服务器的设计, 本文就从起源的角度介绍一下现代网络服务器处理并发连接的思路, 例子就用java提供的API. 1.单线程同步阻塞式服务器及操作系统API 此种是最简单的socket服务 ...
- MVVM架构~Knockoutjs系列之js接收C#数据集合的方式
返回目录 在controller里将数据拿到,并且存储到ViewBag对象里,最后在View上显示出来,这是传统的MVC开发方式,事实上引入Knockoutjs以后,这种方式还是适合的,Knockou ...
- Java程序员的日常 —— 多进程开发IO阻塞问题
本篇仍旧是源于最近的工作,总结一下纪念那些年埋下的坑... 背景故事 需求:"使用进程方式启动另一个程序!" 开发:"OK! Runtime.getRuntime().e ...
- 常用 sql
一. sql 多个字段拼接 mysql: 1. concat函数 如果连接串中存在NULL,则返回结果为NULL: 例如: select concat('1','2','3') ...
- 浅谈JAVA集合框架
浅谈JAVA集合框架 Java提供了数种持有对象的方式,包括语言内置的Array,还有就是utilities中提供的容器类(container classes),又称群集类(collection cl ...
- 设置easyui input默认值
/*设置input 焦点*/ $(function () { //集体调用 $(".formTextBoxes input").each(function () { $(this) ...
- APP性能测试
方法一: 本地安装安卓模拟器,用LR选择模拟器录制方式录制 方法二: 手机真机需要root,可以在电脑上下载一键root工具(如卓大师),然后手机和电脑用数据线连接,然后root. 在手机上运行 Mo ...
- andriod adt和andriod sdk
今天搭建appium的环境,没有太明白andriod adt和andriod sdk分别是什么东西,经过与开发沟通,大致了解如下,这里记录一下,免得过几天就搞忘了. andriod adt是一个插件, ...
- CSS中如何实现未知尺寸图片垂直居中
在曾经的 淘宝UED 招聘 中有这样一道题目: “使用纯CSS实现未知尺寸的图片(但高宽都小于200px)在200px的正方形容器中水平和垂直居中.” 当然出题并不是随意,而是有其现实的原因,垂直居中 ...
- 【.Net底层剖析】3.用IL来理解属性
.Net底层剖析目录章节 1.[深入浅出.Net IL]1.一个For循环引发的IL 2.[.Net底层剖析]2.stfld指令-给对象的字段赋值 3.[.Net底层剖析]3.用IL来理解属性 未完待 ...