C# 我可以在DataGridView中显示行标题上的行数吗?

C# 我可以在DataGridView中显示行标题上的行数吗?,c#,C#,我的datagridview是从右到左的 当我使用此代码时,数字显示在最后一列 当datagridview从左向右时,此代码是正确的 我想在DataGridView的所有行标题上显示行数和图像 private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e) { using (SolidBrush b = new SolidBrush(DataGridView1.Row

我的datagridview是从右到左的

当我使用此代码时,数字显示在最后一列

当datagridview从左向右时,此代码是正确的

我想在DataGridView的所有行标题上显示行数和图像

private void DataGridView1_RowPostPaint(object sender, DataGridViewRowPostPaintEventArgs e)
{ 
    using (SolidBrush b = new SolidBrush(DataGridView1.RowHeadersDefaultCellStyle.ForeColor)) 
    { 
        e.Graphics.DrawString(e.RowIndex.ToString(), e.InheritedRowStyle.Font, b, e.RowBounds.Location.X + 20, e.RowBounds.Location.Y + 4); 
    }
}

您可以在网格视图标题中显示文本,如下所示

private void dataGridView_RowValidated(object sender, DataGridViewCellEventArgs e)
{
    DataGridView gridView = sender as DataGridView;

    if (gridview !=null)
    {
        gridView.Rows[0].HeaderCell.Value = string.format("Total Number of Rows:  {0}",gridview .Rows.Count);
    }
}
您可以使用该属性


在本例中,此属性用于跟踪DataGridView中的条目数

我没有DataGridView的事件行数据绑定。使用行验证事件,您可以添加标题图像,如以下链接-对于此工作,行验证不是好事件。用户在单击行之前看不到,我强调我的代码工作,而datagridview从左到右,datagridview从右到左代码不工作。