1

I got this code:

    private void Form1_Load(object sender, EventArgs e)
    {
        dataGridView1.Columns.Add(new DataGridViewColumn(new DataGridViewTextBoxCell()));

        List<string> carList = new List<string> { "car1 = red " + '\n'+ "car1 = blue", "car2 = green " + '\n' + "car2 = beige" };

        foreach (string car in carList)
        {
            dataGridView1.Rows.Add(car);
        }
    }

When my form is loaded i want to display the cell value something like

First cell content:

car1 = red ,
car1 = blue

Second cell content:

car2 = green,
car2 = beige

Having the above code the cell content appears as a one line string but interesting is that the content of the cell's tooltip gets the text format that I want.

This is a sample picture with my result: enter image description here

How could I get the same format (as the one from the tooltip) also for the text from the cell ?

Clock
  • 974
  • 3
  • 17
  • 35
  • 3
    Setting `DefaultCellStyle.WrapMode = DataGridViewTriState.True` for your `Column` makes it multi-line. But you also need to set `AutoSizeRowsMode` property of `DataGridView` to `AllCells` to makes the height of row auto-size to show all lines of text. Take a look at this post: [DataGridView with ListBox column](http://stackoverflow.com/a/34842429/3110834) – Reza Aghaei Sep 05 '16 at 21:00
  • Thank you for posts they really point me how to handle this ! Yeap Reza, your post contains a "full" solution. – Clock Sep 05 '16 at 21:12
  • Ok, i will keep that in mind – Clock Sep 06 '16 at 21:51

0 Answers0