Search code examples
c#winformsdatagridviewdatagridviewcolumn

Add values just to one column in DataGridView C#


I have a DataGridView with 6 columns; I want the first column to display the days of the week. And the second column should display a schedule per day. But I want them to display in vertical order, not in horizontal way. But I can't figure out how to do it.

I have it like this:enter image description here

And I want it like this:enter image description here


Solution

  • according to your second picture:

    dataGridView1.Rows.Add(9);
    
    // for days column (1st column)
    dataGridView1[0,0].Value = "Monday";
    dataGridView1[0,3].Value = "Tuesday";
    dataGridView1[0,6].Value = "Wednesday";
    
    // for hours column (3rd column)
    dataGridView1[2,0].Value = "7:00 - 8:00";
    dataGridView1[2,1].Value = "8:00 - 9:00";
    dataGridView1[2,3].Value = "7:00 - 7:50";
    dataGridView1[2,4].Value = "7:50 - 8:20";
    

    Basically

    dataGridView[Column index, Row index].Value is the cell value at those coordinates