[WinForm]DataGridView列自适应

关键代码:

        /// <summary>

        /// 根据cell内容调整其宽度

        /// </summary>

        /// <param name="girdview"></param>

        public static void AutoCellWidth(this DataGridView girdview)

        {

            girdview.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.None;

            girdview.AutoResizeColumns();

            girdview.AllowUserToResizeColumns = true;

        }

你可能感兴趣的:(datagridview)