kogepanmanの日記: DataGridViewのサンプル C#
日記 by
kogepanman
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
dataGridView1.DataSource = bindingSource1;
db = new OdbcConnection("uid=dba;pwd=kanrisya:passwd;dbn=Z0106;dsn=ICS_Z0106");
db.Open();
OdbcDataAdapter adapter = new OdbcDataAdapter("select table_id, table_name from systable order by table_id", db);
OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
}
}
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Data.Odbc;
using System.Drawing;
using System.Text;
using System.Windows.Forms;
namespace DataGridViewTest
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
}
private void Form1_Load(object sender, EventArgs e)
{
try
{
dataGridView1.DataSource = bindingSource1;
db = new OdbcConnection("uid=dba;pwd=kanrisya:passwd;dbn=Z0106;dsn=ICS_Z0106");
db.Open();
OdbcDataAdapter adapter = new OdbcDataAdapter("select table_id, table_name from systable order by table_id", db);
OdbcCommandBuilder builder = new OdbcCommandBuilder(adapter);
DataTable table = new DataTable();
table.Locale = System.Globalization.CultureInfo.InvariantCulture;
adapter.Fill(table);
bindingSource1.DataSource = table;
dataGridView1.AutoResizeColumns(DataGridViewAutoSizeColumnsMode.AllCellsExceptHeader);
}
catch (Exception x)
{
MessageBox.Show(x.Message);
}
}
}
}