bootstrap fuelux datagrid表头怎么添加checkbox多选框
1个回答
2015-01-14 · 知道合伙人数码行家
huanglenzhi
知道合伙人数码行家
向TA提问 私信TA
知道合伙人数码行家
采纳数:117538
获赞数:517195
长期从事计算机组装,维护,网络组建及管理。对计算机硬件、操作系统安装、典型网络设备具有详细认知。
向TA提问 私信TA
关注
展开全部
winform datagridview表头怎么增加复选框,点击表头的复选框,下面行的复选全选或全未选
2011-03-08 14:22
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
publicpartialclass Form1 : Form
{
private DataGridView DataGridView1 =new DataGridView();
private CheckBox CheckBox1 =new CheckBox();
public Form1()
{
InitializeComponent();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
CheckBox1.CheckedChanged += CheckBox1_CheckedChanged;
DataGridView1.CellPainting += DataGridView1_CellPainting;
this.DataGridView1.AllowUserToResizeRows =false;
this.DataGridView1.AllowUserToResizeColumns =false;
this.DataGridView1.Dock = DockStyle.Fill;
this.DataGridView1.Columns.Add(new DataGridViewCheckBoxColumn());
this.DataGridView1.Columns.Add("Column2", "Column2");
for (int i =1; i <=3; i++)
{
this.DataGridView1.Rows.Add(0, "Row"+ i.ToString() +" Column2");
}
this.CheckBox1.Visible =false;
this.CheckBox1.Text ="CheckBox";
this.Controls.Add(DataGridView1);
this.Controls.Add(CheckBox1);
}
privatevoid CheckBox1_CheckedChanged(object send, System.EventArgs e)
{
for (int i =0; i <=this.DataGridView1.RowCount -1; i++)
{
this.DataGridView1.Rows.SharedRow(i).SetValues(CheckBox1.Checked);
}
}
privatevoid DataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex ==-1& e.ColumnIndex ==0)
{
Point p =this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
p.Offset(this.DataGridView1.Left, this.DataGridView1.Top);
this.CheckBox1.Location = p;
this.CheckBox1.Size =this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
this.CheckBox1.Visible =true;
this.CheckBox1.BringToFront();
}
}
}
}
2011-03-08 14:22
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Windows.Forms;
namespace WindowsFormsApplication1
{
publicpartialclass Form1 : Form
{
private DataGridView DataGridView1 =new DataGridView();
private CheckBox CheckBox1 =new CheckBox();
public Form1()
{
InitializeComponent();
}
privatevoid Form1_Load(object sender, EventArgs e)
{
CheckBox1.CheckedChanged += CheckBox1_CheckedChanged;
DataGridView1.CellPainting += DataGridView1_CellPainting;
this.DataGridView1.AllowUserToResizeRows =false;
this.DataGridView1.AllowUserToResizeColumns =false;
this.DataGridView1.Dock = DockStyle.Fill;
this.DataGridView1.Columns.Add(new DataGridViewCheckBoxColumn());
this.DataGridView1.Columns.Add("Column2", "Column2");
for (int i =1; i <=3; i++)
{
this.DataGridView1.Rows.Add(0, "Row"+ i.ToString() +" Column2");
}
this.CheckBox1.Visible =false;
this.CheckBox1.Text ="CheckBox";
this.Controls.Add(DataGridView1);
this.Controls.Add(CheckBox1);
}
privatevoid CheckBox1_CheckedChanged(object send, System.EventArgs e)
{
for (int i =0; i <=this.DataGridView1.RowCount -1; i++)
{
this.DataGridView1.Rows.SharedRow(i).SetValues(CheckBox1.Checked);
}
}
privatevoid DataGridView1_CellPainting(object sender, System.Windows.Forms.DataGridViewCellPaintingEventArgs e)
{
if (e.RowIndex ==-1& e.ColumnIndex ==0)
{
Point p =this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, true).Location;
p.Offset(this.DataGridView1.Left, this.DataGridView1.Top);
this.CheckBox1.Location = p;
this.CheckBox1.Size =this.DataGridView1.GetCellDisplayRectangle(e.ColumnIndex, e.RowIndex, false).Size;
this.CheckBox1.Visible =true;
this.CheckBox1.BringToFront();
}
}
}
}
本回答被提问者和网友采纳
已赞过
已踩过<
评论
收起
你对这个回答的评价是?
推荐律师服务:
若未解决您的问题,请您详细描述您的问题,通过百度律临进行免费专业咨询