Winform中DataGridView获取选中行数据
//获取选中行索引
int index = dvData.CurrentCell.RowIndex;
//获取选中行数据
object objName = dvData.Rows[index].Cells["ClientName"].Value;
string clientName = objName != null ? objName.ToString() : "";
Winform中DataGridView显示行号
//显示行号
private void dvData_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{
using (SolidBrush b = new SolidBrush(this.dvData.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);
}
}
dvData.Columns[0].HeaderCell.Value = "节点名称";