如何获取datagridview行号和列号?
获取datagridview的行号和列号的方法:
private void dataridView1_Cellnter(object sender, DatGridViwCellEventArgs e)
{
iTag = (int)this.Tag;
//if (iTag == 4)
//{
// if (e.ColumnIndex ==3)
// MessageBox.Show("该列为只读列", "提示信息", MesageBoxButtons.OK,
MesageBoxIcon.Inforation);
//}
//获取当前单元格行号和列号
string rowIndex = e.RoIndex.ToString();
string colIdex = e.ColumnIdex.ToString();
}
winform中让datagridview自动显示行号代码如下:
private void gvPurchaseOrder_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(this.gvPurchaseOrder.RowHeadersDefaultCellStyle.ForeColor))
{
e.Graphics.DrawString(Convert.ToString(e.RowIndex + 1, CultureInfo.CurrentUICulture),
e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4);
}
}