sam020:グリッドのプロパティをいろいろ変えるテスト
dataGridのプロパティをいろいろと試す
using System.Data.OleDb; ・・・ private OleDbConnection myConnect; private void Form1_Load(object sender, System.EventArgs e) { //Oracle接続文字列 string strConn; strConn = "Provider=OraOLEDB.Oracle"; strConn += ";Data Source=testdb"; strConn += ";User ID=testuser"; strConn += ";Password=testpass"; //データベース接続確立 myConnect = new OleDbConnection(strConn); } private void Form1_Closing(object sender, System.ComponentModel.CancelEventArgs e) { //データベース切断 myConnect.Close(); } private void button1_Click(object sender, System.EventArgs e) { //SQL文 string strSQL = "SELECT * FROM sam01"; //DataAdapterインスタンスを作成 OleDbDataAdapter myDataAdapter = new OleDbDataAdapter(strSQL,myConnect); //DataSetインスタンスを作成 DataSet myDataSet = new DataSet(); //DataAdapterに格納されているレコードをDataSetに格納する myDataAdapter.Fill(myDataSet); // //グリッド // //dataGridにDataSetの内容を格納する dataGrid1.DataSource = myDataSet; //親行の背景色 dataGrid1.ParentRowsBackColor = Color.Aquamarine; //親行ラベルの表示方法 dataGrid1.ParentRowsLabelStyle = DataGridParentRowsLabelStyle.Both; //親行ラベルの表示/非表示 dataGrid1.ParentRowsVisible = false; //列の横幅 dataGrid1.PreferredColumnWidth = 100; //行の高さ dataGrid1.PreferredRowHeight = 10; //グリッド全体を左から右に表示するか、右から左に表示するか dataGrid1.RightToLeft = RightToLeft.No; //行ヘッダーの表示/非表示 dataGrid1.RowHeadersVisible = true; //行ヘッダーの幅 dataGrid1.RowHeaderWidth = 10; //選択された行の背景色 dataGrid1.SelectionBackColor = Color.Red; //選択された行の文字色 dataGrid1.SelectionForeColor = Color.Yellow; //グリッドの表題 dataGrid1.CaptionText = "テストデータ"; //グリッドの表題の表示/非表示 dataGrid1.CaptionVisible = false; //MessageBox.Show("成功"); } private void dataGrid1_CurrentCellChanged(object sender, System.EventArgs e) { int intRow,intCol; intCol = dataGrid1.CurrentCell.ColumnNumber; intRow = dataGrid1.CurrentCell.RowNumber; intCol++; intRow++; MessageBox.Show("列:" + intCol.ToString("00") + "/行:" + intRow.ToString("00")); } |
最初の画面
ボタンを押した時
dataGridをクリックした時