繁体   English   中英

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

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

我的datagridview是从右到左。

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

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

您可以使用DataGridView.RowCount属性。

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

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

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