0

Hello my dear friends,

I have a DataGridView and made a database connection to get a table.
If the user clicks on the button he gets the information in DataGridView object.

It looks like this:

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

But I want to have numeric numbers on the left of the DataGridView.
So I tried:

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

But "row" and the "HeaderCell" class gives a error.

Jimi
  • 29,621
  • 8
  • 43
  • 61
Burak
  • 235
  • 1
  • 2
  • 12
  • What is the error message that you get? And I am not quite sure what exactly do you mean by count? – Prashant Tiwari Dec 06 '18 at 10:43
  • Possible duplicate of [Show row number in row header of a DataGridView](https://stackoverflow.com/questions/9581626/show-row-number-in-row-header-of-a-datagridview) – Markus Deibel Dec 06 '18 at 10:52
  • Use the `RowPostPaint` event to Draw the row number. This will take care of the numbering when you add/remove a row. – Jimi Dec 06 '18 at 10:52
  • Possible duplicate of https://stackoverflow.com/questions/9581626/show-row-number-in-row-header-of-a-datagridview – Markus Deibel Dec 06 '18 at 10:52

0 Answers0