How to set the DataGridViewCell to automatically word wrap?

前端 未结 5 908
清酒与你
清酒与你 2020-12-16 11:39

The code below which I found on MSN did not worked to automatically word-wrap a cell:

dataGridView.Columns[0].AutoSizeMode = DataGridViewAutoSizeColumnMode.D         


        
5条回答
  •  南笙
    南笙 (楼主)
    2020-12-16 11:53

    You could also make it, in this way

    DataGridViewTextBoxColumn comments = new DataGridViewTextBoxColumn();
    {
        comments.Name = "comments";
        comments.HeaderText = "Comments";
        comments.AutoSizeMode = DataGridViewAutoSizeColumnMode.AllCells;
        comments.DefaultCellStyle.WrapMode = DataGridViewTriState.True;
        this.dataGridView1.Columns.Add(comments);
    }
    

提交回复
热议问题