自动生成行号datagridview第一列c#? [英] auto generate row number datagridview first column c#?

查看:745
本文介绍了自动生成行号datagridview第一列c#?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在表格中有c#的窗体我有一个从oracle表填充数据的datagridview ...我想让datagridview的第一个索引成为一系列数字,例如第一行1和第二行2 ....,和显示的数据从第二个索引开始

i have windows form in c# on the form i have a datagridview that populate data from an oracle table ... i want to make the first index of the datagridview a series of number for example for first row 1 and for second row 2 ...., and the displayed data Begin from the second index

推荐答案

在c#中的datagridview中生成序列号


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


dataGridView1.DataBindingComplete += (o, e) =>
    {
        foreach (DataGridViewRow row in dataGridView1.Rows)
            row.HeaderCell.Value = (row.Index + 1).ToString();
    };


这篇关于自动生成行号datagridview第一列c#?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆