如何在dataGridView行中显示数字

时间:2018-12-06 10:15:08

标签: c# visual-studio-2010 datagridview

你好,亲爱的朋友,

我有一个DataGridView并建立了数据库连接以获取表。
如果用户单击按钮,他将在DataGridView对象中获取信息。

它看起来像这样:

 private void button3_Click(object sender, EventArgs e)
{
    dataGridView1.Refresh();
    dataGridView1.Columns.Clear();
    clsMSSQL.clsMSSQL mssql = new clsMSSQL.clsMSSQL(2);
    string sql = ("select CCase.RefNo AS Az, EventTemplate.EventCode AS Vorgang from ikaros.CCase join ikaros.Event on CCase.ID = Event.CCaseID join ikaros.EventTemplate on Event.EventTemplateID  = EventTemplate.ID where EventTemplate.EventCode='IRVB' and Event.EventDate ='2014-07-03' order by CCase.RefNo ASC");
    mssql.Query(sql);
    mssql.Fetch();
    dataGridView1.ColumnCount = 2;
    dataGridView1.Columns[0].Name = "Aktenzeichen";
    dataGridView1.Columns[1].Name = "Vorgang";

    while (!mssql.eof)
    {
        string[] arr_row = new string[2];

        arr_row[0] = mssql.GetString("Az");
        arr_row[1] = mssql.GetString("Vorgang");
        dataGridView1.Rows.Add(arr_row);
        mssql.Fetch();
    }
    dataGridView1.EndEdit();
    dataGridView1.Refresh();
}

但是我想在DataGridView的左侧添加数字。
所以我尝试了:

  

row.HeaderCell.Value = String.Format(“ {0}”,row.Index +1);

但是“ row”和“ HeaderCell”类给出了错误。

0 个答案:

没有答案