開発環境 |
Microsoft Visual C++ 2010 Express (SP1) |
実行環境 |
Microsoft Windows XP Home Edition (SP3) |
プロジェクトの種類 |
空の CLR プロジェクト |
プロジェクト名 |
ClrDgv2 |
参考
ClrDgv2.cpp
#pragma comment(linker, "/subsystem:windows /entry:main")
// アセンブリ
#using <System.dll>
#using <System.Data.dll>
#using <System.Drawing.dll>
#using <System.Windows.Forms.dll>
// 名前空間
using namespace System;
using namespace System::Data;
using namespace System::Data::Odbc;
using namespace System::Drawing;
using namespace System::Threading;
using namespace System::Windows::Forms;
ref class Form1 : Form
{
public:
Form1(void)
{
InitializeComponent();
InitializeDGV();
}
private:
DataGridView^ dgv;
BindingSource^ bs;
void InitializeComponent(void)
{
dgv = gcnew DataGridView;
bs = gcnew BindingSource;
SuspendLayout();
// dgv
// dgv->Location = Point(96, 71);
// dgv->Size = Drawing::Size(321, 286);
dgv->Dock = DockStyle::Fill;
// Form1
Text = "ClrDgv2";
ClientSize = Drawing::Size(800, 600);
Controls->Add(dgv);
ResumeLayout(false);
}
void InitializeDGV(void)
{
try {
dgv->AutoGenerateColumns = true;
bs->DataSource = GetData("select * from 09TOCHIG.CSV");
dgv->DataSource = bs;
dgv->AutoSizeRowsMode =
DataGridViewAutoSizeRowsMode::DisplayedCellsExceptHeaders;
dgv->BorderStyle = BorderStyle::Fixed3D;
dgv->EditMode = DataGridViewEditMode::EditOnEnter;
}
catch (OdbcException^) {
MessageBox::Show("OdbcException");
Thread::CurrentThread->Abort();
}
catch (Exception^ ex) {
MessageBox::Show(ex->ToString());
}
}
DataTable^ GetData(String^ sql)
{
String^ connStr = "driver={Microsoft Text Driver (*.txt; *.csv)}; dbq=C:\\tmp";
OdbcConnection^ conn = gcnew OdbcConnection(connStr);
OdbcCommand^ command = gcnew OdbcCommand(sql, conn);
OdbcDataAdapter^ adapter = gcnew OdbcDataAdapter;
adapter->SelectCommand = command;
DataTable^ table = gcnew DataTable;
adapter->Fill(table);
return table;
}
};
int main()
{
Application::Run(gcnew Form1);
return 0;
}
最終更新:2012年10月25日 09:34