如何显示DataGridView行号?
解决方案 »
- 第一个建的TextBox,在运行时会某人获取焦点(focus),如何改变,不让其获取焦点!!!
- 如何对COMBOBOX显示类容初始化?
- char能不能表示为空?
- C#画图的问题,高手进!
- 菜鸟提问 Inconsistent accessibility
- Repeater中怎样根据数据库中列的值不同,而有相应的显示啊,例如,是1就显示“隐藏”,是2就显示“显示”啊
- 为什么我0分的帖子未结也要扣信誉分?
- 用C#开发应用程序
- 请教!winform如何传数据给网页?
- Web Service里调用存储过程时出错,哪位帮看看代码?急!!!
- DataSet导出XML丢失空字段的问题
- 请问如何 在 GridView控件中 添加一个 插入按钮
{
this.textBox1.Text = this.dataGridView1.CurrentRow.Index.ToString();
}如果希望在dataGridView上直接添加行标头 可以如下做 不过这个代码还有些bug 仅供参考 private void dataGridView1_Paint(object sender, System.Windows.Forms.PaintEventArgs e)
{ int row = 0; int yDelta = dataGridView1.GetCellDisplayRectangle(row, 0, false).Height + 1; int y = dataGridView1.GetCellDisplayRectangle(row, 0, false).Top + 2; CurrencyManager cm = (CurrencyManager)this.BindingContext[dataGridView1.DataSource, dataGridView1.DataMember]; while (y < dataGridView1.Height - yDelta && row < cm.Count)
{ //get & draw the header text... string text = string.Format("{0}", row); e.Graphics.DrawString(text, dataGridView1.Font, new SolidBrush(Color.Black), 12, y); y += yDelta; row++;
} }
{
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(e.RowIndex.ToString(System.Globalization.CultureInfo.CurrentCulture),
dataGridView1.DefaultCellStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}
private void dataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
//添加行号
using (SolidBrush b = new SolidBrush(dataGridView1.RowHeadersDefaultCellStyle.ForeColor))
{
string linenum = e.RowIndex.ToString();
int linen = 0;
linen = Convert.ToInt32(linenum) + 1;
string line = linen.ToString();
e.Graphics.DrawString(line, e.InheritedRowStyle.Font, b, e.RowBounds.Location.X, e.RowBounds.Location.Y + 5);
SolidBrush B = new SolidBrush(Color.Red);
}
}
{
当前网格单元格.value=e.RowIndex
}
{
Rectangle rectangle = new Rectangle(e.RowBounds.Location.X,e.RowBounds.Location.Y,dgv_show.RowHeadersWidth - 4,e.RowBounds.Height);
TextRenderer.DrawText(e.Graphics,(e.RowIndex + 1).ToString(),dgv_show.RowHeadersDefaultCellStyle.Font,rectangle,dgv_show.RowHeadersDefaultCellStyle.ForeColor,TextFormatFlags.VerticalCenter | TextFormatFlags.Right);
}
要是有些更高的要求,请使用自定控件,还不行,[email protected]