- using System;
- using System.Collections.Generic;
- using System.ComponentModel;
- using System.Data;
- using System.Drawing;
- using System.Linq;
- using System.Text;
- using System.Threading.Tasks;
- using System.Windows.Forms;
-
- namespace WindowsFormsApplication1
- {
- public partial class Form1 : Form
- {
- DataGridView DataGridView1;
-
- public Form1()
- {
- InitializeComponent();
-
- // DataTableの作成
- DataTable dataTable = new DataTable();
- dataTable.Columns.Add("列1", typeof(string));
- dataTable.Columns.Add("列2", typeof(string));
- dataTable.Columns.Add("列3", typeof(string));
- dataTable.Columns.Add("列4", typeof(string));
- dataTable.Columns.Add("列5", typeof(string));
- dataTable.Rows.Add("1-1", "1-2", "1-3", "1-4", "1-5");
- dataTable.Rows.Add("2-1", "2-2", "2-3", "2-4", "2-5");
- dataTable.Rows.Add("3-1", "3-2", "3-3", "3-4", "3-5");
- dataTable.Rows.Add("4-1", "4-2", "4-3", "4-4", "4-5");
- dataTable.Rows.Add("5-1", "5-2", "5-3", "5-4", "5-5");
- dataTable.Rows.Add("6-1", "6-2", "6-3", "6-4", "6-5");
- dataTable.Rows.Add("7-1", "7-2", "7-3", "7-4", "7-5");
- dataTable.Rows.Add("8-1", "8-2", "8-3", "8-4", "8-5");
-
- // DataGridViewの作成
- DataGridView1 = new DataGridView();
- DataGridView1.DataSource = dataTable;
-
- // DataGridViewの横幅、縦幅を指定
- DataGridView1.Size = new Size(300, 150);
-
- // DataGridViewの位置を指定
- DataGridView1.Location = new Point(50, 10);
-
- // 画面から行を追加できないようにする
- DataGridView1.AllowUserToAddRows = false;
-
- // FormにDataGridViewを追加
- this.Controls.Add(DataGridView1);
- }
-
- /**
- * ウィンドウ枠固定
- */
- private void button1_Click(object sender, EventArgs e)
- {
- // 列の固定
- DataGridView1.Columns[0].Frozen = true;
- // 行の固定
- DataGridView1.Rows[0].Frozen = true;
- }
-
- /**
- * ウィンドウ枠固定解除
- */
- private void button2_Click(object sender, EventArgs e)
- {
- DataGridView1.Columns[0].Frozen = false;
- DataGridView1.Rows[0].Frozen = false;
- }
- }
- }
|