LoginSignup
0
1

More than 5 years have passed since last update.

Visual Studio / Windows Forms Application > DataGridView > 列の幅を変更する > 指定 / 自動調整

Last updated at Posted at 2017-04-21
動作環境
Windows 7 Pro (32bit)
Microsoft Visual Studio 2017 Community
Sublime Text 2

DataGridView において、列の幅を変更したい。

Form1.cs
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;
using System.IO; 

namespace _170421_helloWorld
{
    public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Shown(object sender, EventArgs e)
        {
            string alist = "data1,data2,data3";
            string[] elem = alist.Split(',');
            for(int idx=0; idx<3; idx++)
            {
                dataGridView1.Rows.Add(elem);
            }
        }

        private void B_narrower_Click(object sender, EventArgs e)
        {
            dataGridView1.Columns[1].Width -= 20; 
        }

        private void B_autosize_Click(object sender, EventArgs e)
        {
            dataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.AllCells;
        }
    }
}

自動設定時の結果。

work.png

0
1
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
0
1