码迷,mamicode.com
首页 > Windows程序 > 详细

C# Winfrom DataGridView常用设置

时间:2019-09-27 15:08:50      阅读:142      评论:0      收藏:0      [点我收藏+]

标签:oid   selectall   value   space   select   return   wpost   orm   graphics   

DataGridView常用设置

using System;
using System.Collections.Generic;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;

namespace ZB.QueueSys.Common
{
    public class DataGridViewHelper
    {
        private static DataGridViewHelper instance;
        public static DataGridViewHelper Instance
        {
            get
            {
                if (instance == null) instance = new DataGridViewHelper();
                return DataGridViewHelper.instance;
            }
        }

        public void SelectAllDgv(DataGridView dgv, string cellName, bool isChecked)
        {
            int count = dgv.Rows.Count;
            for (int i = 0; i < count; i++)
            {
                dgv.Rows[i].Cells[cellName].Value = isChecked;
            }
        }

        public void SetDgvRowColor(DataGridView dgv)
        {
            dgv.AlternatingRowsDefaultCellStyle.BackColor = Color.FromArgb(204, 224, 233);
        }

        public void SetDgvRowColor(DataGridView dgv, Color color)
        {
            dgv.AlternatingRowsDefaultCellStyle.BackColor = color;
            dgv.AutoGenerateColumns = false;
        }

        public void SetDgvStyle(DataGridView dgv, Color color)
        {
            dgv.AlternatingRowsDefaultCellStyle.BackColor = color;
            dgv.AutoGenerateColumns = false;
        }

        /// <summary>
        /// 重绘DataGridView
        /// </summary>
        /// <param name="dgv"></param>
        /// <param name="e"></param>
        public void PaintDgv(DataGridView dgv, DataGridViewRowPostPaintEventArgs e)
        {
            try
            {
                SolidBrush b = new SolidBrush(dgv.RowHeadersDefaultCellStyle.ForeColor);
                e.Graphics.DrawString((e.RowIndex + 1).ToString(System.Globalization.CultureInfo.CurrentUICulture),
                    dgv.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 5, e.RowBounds.Location.Y + 4);
            }
            catch { return; }
        }

    }
}

  

C# Winfrom DataGridView常用设置

标签:oid   selectall   value   space   select   return   wpost   orm   graphics   

原文地址:https://www.cnblogs.com/YYkun/p/11597963.html

(0)
(0)
   
举报
评论 一句话评论(0
登录后才能评论!
© 2014 mamicode.com 版权所有  联系我们:gaon5@hotmail.com
迷上了代码!