求助各位:
我现在想锁定dataGridView 箭头列,也就是用户不可以拖拉列宽度那种,但是 dataGridView 其他列宽度可以拖拉,怎么来实现呢?还有就是想在 dataGridView 箭头列显示序列号码可以实现? 哪位高手指点一下,或者给个代码参考一下 谢谢!
我现在想锁定dataGridView 箭头列,也就是用户不可以拖拉列宽度那种,但是 dataGridView 其他列宽度可以拖拉,怎么来实现呢?还有就是想在 dataGridView 箭头列显示序列号码可以实现? 哪位高手指点一下,或者给个代码参考一下 谢谢!
DataGridView1.Columns[0].Frozen = true;
DataGridView1.Columns[0].Frozen = true;
这只是锁定了 第一列 我想要的是锁定 dataGridView 的 箭头列
//添加行号
protected override void OnRowPostPaint(System.Windows.Forms.DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(this.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 10, e.RowBounds.Location.Y + e.RowBounds.Height / 2 - e.InheritedRowStyle.Font.Size / 2);
}
base.OnRowPostPaint(e);
}
为了表示行号,我们可以在DataGridView的RowPostPaint事件中进行绘制。 private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,
e.RowBounds.Location.Y,
dataGridView1.RowHeadersWidth - 4,
e.RowBounds.Height); TextRenderer.DrawText(e.Graphics, (e.RowIndex + 1).ToString(),
dataGridView1.RowHeadersDefaultCellStyle.Font,
rectangle,
dataGridView1.RowHeadersDefaultCellStyle.ForeColor,
TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
锁定 dataGridView 的 箭头列
把dataGridView 的属性
RowHeadersWidthSizeMode设置为DisableResizing就行了