重要的是怎么把列标题设为CheckBox,
除了定义一个CheckBox,然后硬画到DataGridView列标题那栏里面,还有什么办法啊,
因为这样硬画的话,会导致拖动DataGridView的横向滚动条的话,CheckBox那列没有被拖动
14 个解决方案
#1
mark up 帮顶
#2
谢谢楼上的,
#3
这里有一篇salu的文章:
Datagridview Checkbox Select All
采用了自定义的DataGridViewColumnHeaderCell,并用CheckBoxRenderer来画单选框,考虑得比较周全。
采用了自定义的DataGridViewColumnHeaderCell,并用CheckBoxRenderer来画单选框,考虑得比较周全。
#4
谢谢,我去看看
#5
学习
顶
顶
#6
学习
#7
我弄了,但是有问题啊,第一行上的checkbox始终没打上
#8
托一个单独的CheckBox1,设置合适的大小,
单鼠标移到指定的列头时显示出来到合适的位置
在CheckBox1里写代码改变整个列的Checked值..
X= DataGridView.Location.X+(DataGridView.Columns[0].Width+......+DataGridView.Columns[i-1].Width)
Y= DataGridView.Location.X
CheckBox1.Size=DataGridView.Columns[i-1].HeaderCell.Size
单鼠标移到指定的列头时显示出来到合适的位置
在CheckBox1里写代码改变整个列的Checked值..
X= DataGridView.Location.X+(DataGridView.Columns[0].Width+......+DataGridView.Columns[i-1].Width)
Y= DataGridView.Location.X
CheckBox1.Size=DataGridView.Columns[i-1].HeaderCell.Size
#9
汗。。
Y= DataGridView.Location.Y
看看可以不
Y= DataGridView.Location.Y
看看可以不
#10
private void SetComboxUnitsInCurrentCell(int columnIndex, int rowIndex)
{
cbUnits.Height = dgvList.CurrentCell.Size.Height + 4;
cbUnits.Width = dgvList.CurrentCell.Size.Width - 1;
Point currentcelllocation = GetCellLocation(columnIndex, rowIndex);
cbUnits.Location = new Point(currentcelllocation.X + 1, currentcelllocation.Y + 1);
dgvList.DefaultCellStyle.SelectionBackColor = Color.White;
cbUnits.Visible = true;
cbUnits.Focus();
}
private Point GetCellLocation(int columnIndex, int rowIndex)
{
int xoffset = dgvList.Location.X + dgvList.RowHeadersWidth;
int yoffset = dgvList.Location.Y + dgvList.ColumnHeadersHeight;
for (int i = 0; i < columnIndex; i++)
{
xoffset += dgvList.Columns[i].Width;
}
xoffset -= dgvList.HorizontalScrollingOffset;
for (int i = 0; i < rowIndex; i++)
{
yoffset += dgvList.Rows[i].Height;
}
yoffset -= dgvList.VerticalScrollingOffset;
return new Point(xoffset, yoffset);
}
private void HideUnits()
{
cbUnits.Visible = cbUnits.Focused;
if (!cbUnits.Visible)
{
dgvList.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
}
}
private void cbUnits_MouseLeave(object sender, EventArgs e)
{
cbUnits.LostFocus += delegate { HideUnits(); };
}
俺以前写的一个
{
cbUnits.Height = dgvList.CurrentCell.Size.Height + 4;
cbUnits.Width = dgvList.CurrentCell.Size.Width - 1;
Point currentcelllocation = GetCellLocation(columnIndex, rowIndex);
cbUnits.Location = new Point(currentcelllocation.X + 1, currentcelllocation.Y + 1);
dgvList.DefaultCellStyle.SelectionBackColor = Color.White;
cbUnits.Visible = true;
cbUnits.Focus();
}
private Point GetCellLocation(int columnIndex, int rowIndex)
{
int xoffset = dgvList.Location.X + dgvList.RowHeadersWidth;
int yoffset = dgvList.Location.Y + dgvList.ColumnHeadersHeight;
for (int i = 0; i < columnIndex; i++)
{
xoffset += dgvList.Columns[i].Width;
}
xoffset -= dgvList.HorizontalScrollingOffset;
for (int i = 0; i < rowIndex; i++)
{
yoffset += dgvList.Rows[i].Height;
}
yoffset -= dgvList.VerticalScrollingOffset;
return new Point(xoffset, yoffset);
}
private void HideUnits()
{
cbUnits.Visible = cbUnits.Focused;
if (!cbUnits.Visible)
{
dgvList.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
}
}
private void cbUnits_MouseLeave(object sender, EventArgs e)
{
cbUnits.LostFocus += delegate { HideUnits(); };
}
俺以前写的一个
#11
谢谢你,我试试
#12
路过学习
#13
学习,顶
#14
学习
#1
mark up 帮顶
#2
谢谢楼上的,
#3
这里有一篇salu的文章:
Datagridview Checkbox Select All
采用了自定义的DataGridViewColumnHeaderCell,并用CheckBoxRenderer来画单选框,考虑得比较周全。
采用了自定义的DataGridViewColumnHeaderCell,并用CheckBoxRenderer来画单选框,考虑得比较周全。
#4
谢谢,我去看看
#5
学习
顶
顶
#6
学习
#7
我弄了,但是有问题啊,第一行上的checkbox始终没打上
#8
托一个单独的CheckBox1,设置合适的大小,
单鼠标移到指定的列头时显示出来到合适的位置
在CheckBox1里写代码改变整个列的Checked值..
X= DataGridView.Location.X+(DataGridView.Columns[0].Width+......+DataGridView.Columns[i-1].Width)
Y= DataGridView.Location.X
CheckBox1.Size=DataGridView.Columns[i-1].HeaderCell.Size
单鼠标移到指定的列头时显示出来到合适的位置
在CheckBox1里写代码改变整个列的Checked值..
X= DataGridView.Location.X+(DataGridView.Columns[0].Width+......+DataGridView.Columns[i-1].Width)
Y= DataGridView.Location.X
CheckBox1.Size=DataGridView.Columns[i-1].HeaderCell.Size
#9
汗。。
Y= DataGridView.Location.Y
看看可以不
Y= DataGridView.Location.Y
看看可以不
#10
private void SetComboxUnitsInCurrentCell(int columnIndex, int rowIndex)
{
cbUnits.Height = dgvList.CurrentCell.Size.Height + 4;
cbUnits.Width = dgvList.CurrentCell.Size.Width - 1;
Point currentcelllocation = GetCellLocation(columnIndex, rowIndex);
cbUnits.Location = new Point(currentcelllocation.X + 1, currentcelllocation.Y + 1);
dgvList.DefaultCellStyle.SelectionBackColor = Color.White;
cbUnits.Visible = true;
cbUnits.Focus();
}
private Point GetCellLocation(int columnIndex, int rowIndex)
{
int xoffset = dgvList.Location.X + dgvList.RowHeadersWidth;
int yoffset = dgvList.Location.Y + dgvList.ColumnHeadersHeight;
for (int i = 0; i < columnIndex; i++)
{
xoffset += dgvList.Columns[i].Width;
}
xoffset -= dgvList.HorizontalScrollingOffset;
for (int i = 0; i < rowIndex; i++)
{
yoffset += dgvList.Rows[i].Height;
}
yoffset -= dgvList.VerticalScrollingOffset;
return new Point(xoffset, yoffset);
}
private void HideUnits()
{
cbUnits.Visible = cbUnits.Focused;
if (!cbUnits.Visible)
{
dgvList.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
}
}
private void cbUnits_MouseLeave(object sender, EventArgs e)
{
cbUnits.LostFocus += delegate { HideUnits(); };
}
俺以前写的一个
{
cbUnits.Height = dgvList.CurrentCell.Size.Height + 4;
cbUnits.Width = dgvList.CurrentCell.Size.Width - 1;
Point currentcelllocation = GetCellLocation(columnIndex, rowIndex);
cbUnits.Location = new Point(currentcelllocation.X + 1, currentcelllocation.Y + 1);
dgvList.DefaultCellStyle.SelectionBackColor = Color.White;
cbUnits.Visible = true;
cbUnits.Focus();
}
private Point GetCellLocation(int columnIndex, int rowIndex)
{
int xoffset = dgvList.Location.X + dgvList.RowHeadersWidth;
int yoffset = dgvList.Location.Y + dgvList.ColumnHeadersHeight;
for (int i = 0; i < columnIndex; i++)
{
xoffset += dgvList.Columns[i].Width;
}
xoffset -= dgvList.HorizontalScrollingOffset;
for (int i = 0; i < rowIndex; i++)
{
yoffset += dgvList.Rows[i].Height;
}
yoffset -= dgvList.VerticalScrollingOffset;
return new Point(xoffset, yoffset);
}
private void HideUnits()
{
cbUnits.Visible = cbUnits.Focused;
if (!cbUnits.Visible)
{
dgvList.DefaultCellStyle.SelectionBackColor = SystemColors.Highlight;
}
}
private void cbUnits_MouseLeave(object sender, EventArgs e)
{
cbUnits.LostFocus += delegate { HideUnits(); };
}
俺以前写的一个
#11
谢谢你,我试试
#12
路过学习
#13
学习,顶
#14
学习