开发者

how to break column data of a single row in datagridview manually?

开发者 https://www.devze.com 2023-03-27 02:43 出处:网络
code while (dr.Read()) { string s = dr[\"Title\"].ToString() + Environment.NewLine + dr[\"Description\"].ToString();

code

while (dr.Read())  
{  
    string s = dr["Title"].ToString() + Environment.NewLine + dr["Description"].ToString();  
   开发者_如何转开发 row["Title"]= s.Trim();  
    dt.Rows.Add(row["Title"]);  
}  

i want to break the line in my datagridview.i have row value with "name subject",i want to split it as "name"(newline)"subject" in the same row itself.


Is the problem that line returns are not being displayed in cells in your DataGridView?

If so you need to set the DataGridViewCellStyle.WrapMode Property of the Column you want to see line returns on to DataGridViewTriState.True.

After you do that the Cells in that column will display line breaks within a cell using Environment.NewLine, \n, etc.


You need to set someColumn.DefaultCellStyle.WrapMode = DataGridViewTriState.True; on whatever column you want for it to display multiple lines in.


did you try using: dt.Rows.Add(row["Title"].ToString().Replace(" ", "\r\n"));

0

精彩评论

暂无评论...
验证码 换一张
取 消