0

My code :

        DataTable dt = new DataTable();
        dt.Columns.Add("#", typeof(string));
        dt.Columns.Add("Date", typeof(string));
        dt.Columns.Add("OrderID", typeof(string));
        dt.Columns.Add("info", typeof(string));

        for (int i = 1; i <= 10; i++)
        {
          dt.Rows.Add(i,"date","OrderID","info")
        }

I want to fix width of cell in every Rows of Gridview and when my text is full of width my text will be wrap newline. thank you.

KPTH
  • 91
  • 1
  • 2
  • 12

2 Answers2

0

In c# winform gridview there WrapMode property that can meet your need

dgvmydgv.DefaultCellStyle.WrapMode =DataGridViewTriState.True;

thus for your case if the gridview is dt then

dt.DefaultCellStle.Wrapmode=DataDataGridViewTriState.True; newline is applied to every texts that exceed the width

DANIEL NGAHU
  • 51
  • 2
  • 11
0

You also need to set

DataGridView.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells

(along with what you have done) for word-wrap to work.

with Wrap Mode To work

Lucifer
  • 1,594
  • 2
  • 18
  • 32