CSharp examples for System.Windows.Forms:DataGridView
autosize DataGridView
using System.Windows.Forms; using System.Text; using System.Linq; using System.Drawing; using System.Collections.Generic; using System;/*from w w w .j a va 2s .c o m*/ public class Main{ public static void autosizeGrid(DataGridView dataGrid, int tama?o=12) { dataGrid.ForeColor = Color.Black; dataGrid.AllowUserToOrderColumns = true; dataGrid.AllowUserToResizeColumns = true; dataGrid.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill; dataGrid.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells; dataGrid.DefaultCellStyle.Font = new Font("Segoe UI", tama?o); dataGrid.DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGrid.AlternatingRowsDefaultCellStyle.BackColor = Color.AliceBlue; dataGrid.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", tama?o, FontStyle.Bold); dataGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGrid.ColumnHeadersDefaultCellStyle.Font = new Font("Segoe UI", tama?o, FontStyle.Bold); dataGrid.ColumnHeadersDefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter; dataGrid.AllowUserToAddRows = false; dataGrid.RowHeadersVisible = false; dataGrid.ReadOnly = false; dataGrid.SelectionMode = DataGridViewSelectionMode.FullRowSelect; dataGrid.AllowUserToAddRows = false; dataGrid.AllowUserToDeleteRows = false; } }