打开APP
userphoto
未登录

开通VIP,畅享免费电子书等14项超值服

开通VIP
dataGridView几个小技巧
1)dataGridView隔行变色
RowsDefaultCellStyle :获取或设置应用于 DataGridView 的行单元格的默认样式。
AlternatingRowsDefaultCellStyle 属性:获取或设置应用于 DataGridView 的奇数行的默认单元格样式。
  1. dataGridView1.RowsDefaultCellStyle.BackColor = Color.Aqua;  
  2. dataGridView1.AlternatingRowsDefaultCellStyle.BackColor = Color.Beige;    
2)dataGridView表头加checkbox全选的方法
  1. public class AddCheckBoxToDataGridView  
  2.         {  
  3.             public static System.Windows.Forms.DataGridView dgv;  
  4.             public static void AddFullSelect()  
  5.             {                  
  6.                 if (dgv.Rows.Count < 1)  
  7.                 {  
  8.                     return;  
  9.                 }  
  10.                 System.Windows.Forms.CheckBox ckBox = new System.Windows.Forms.CheckBox();                               
  11.                 System.Drawing.Rectangle rect = dgv.GetCellDisplayRectangle(0, -1, true);  
  12.                 ckBox.Size = new System.Drawing.Size(dgv.Columns[1].Width - 12, 12); //大小                 
  13.                 Point point = new Point(rect.X + 10, rect.Y + 3);  
  14.                 ckBox.Location = point;//位置  
  15.                 ckBox.CheckedChanged += new EventHandler(ckBox_CheckedChanged);  
  16.                 dgv.Controls.Add(ckBox);  
  17.             }  
  18.             static void ckBox_CheckedChanged(object sender, EventArgs e)  
  19.             {  
  20.                 for (int i = 0; i < dgv.Rows.Count; i++)  
  21.                 {  
  22.                     dgv.Rows[i].Cells[0].Value = ((System.Windows.Forms.CheckBox)sender).Checked;  
  23.                 }  
  24.                 dgv.EndEdit();  
  25.             }  
  26.         }    
3)鼠标拖动窗口大小时,设定窗口最小尺寸
private void GetSendBankMsg_ResizeEnd(object sender, EventArgs e)        {            if (this.Width <= 500)                           this.Width = 500;              if (this.Height <= 335)                            this.Height = 335;                    }

4)删除DataGridView没有数据时的默认空白行
dataGridView1.AllowUserToAddRows  = false;
5)让DataGridView的所有列正好占据着整个DataGridView的宽度
把AutoSizeColumnsMode设置为FIll就行了

本站仅提供存储服务,所有内容均由用户发布,如发现有害或侵权内容,请点击举报
打开APP,阅读全文并永久保存 查看更多类似文章
猜你喜欢
类似文章
【热】打开小程序,算一算2024你的财运
DataGridView控件用法(一)绑定数据
DataGridView样式(一)
C#打印DataGridView的详细代码
DataGridView使用技巧(集)
Excel 163种使用技巧(71-80)
C# Winform中让DataGridView单元格显示图片 - ailixin_200...
更多类似文章 >>
生活服务
热点新闻
分享 收藏 导长图 关注 下载文章
绑定账号成功
后续可登录账号畅享VIP特权!
如果VIP功能使用有故障,
可点击这里联系客服!

联系客服