Show row number in row header of a DataGridView

前端 未结 11 2371
野性不改
野性不改 2020-12-01 06:17

Is it possible to show row number in the row header of a DataGridView?

I\'m trying with this code, but it doesn\'t work:

    pri         


        
11条回答
  •  无人及你
    2020-12-01 06:56

    Based on this viedo: VB.net-Auto generate row number to datagridview in windows application-winforms, you can set the DataSource and this code puts the rows numbers, works like a charm.

    private void DataGrid_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        // Add row number
        (sender as DataGridView).Rows[e.RowIndex].HeaderCell.Value = (e.RowIndex+1).ToString();
    }
    

提交回复
热议问题