简体   繁体   English

我可以在DataGridView的RowHeaders上显示行数吗?

[英]Can I display number of row on RowHeaders in the DataGridView?

my datagridview is right to left. 我的datagridview是从右到左。

when i use this code , numbers show on last column. 当我使用此代码时,数字显示在最后一列。

when datagridview is left to right this code is correct. 当datagridview从左到右时,此代码是正确的。

I want to display number of row and image on all RowHeader of DataGridView; 我想在DataGridView的所有RowHeader上显示行数和图像数;

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); 
    }
}

You can use the DataGridView.RowCount Property. 您可以使用DataGridView.RowCount属性。

In this example, this property is used to track the number of entries in a DataGridView 在此示例中,此属性用于跟踪DataGridView中的条目数

You can display Text in grid view header like following. 您可以在网格视图标题中显示文本,如下所示。

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);
    }
}

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM