如何在datagridview中添加新行? [英] How to put a new line in a datagridview?

查看:101
本文介绍了如何在datagridview中添加新行?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

以下是代码:

Here's the code:

string newLine = ((char)10).ToString() + ((char)13).ToString();
               string n = ((char)10).ToString();
               cmd.Connection = con;
               cmd.CommandText = string.Format(@"UPDATE tblAuditTrailUsers SET [Actions]='The user deleted '" + "'" + dgvUserInfo.CurrentRow.Cells[3].Value + "'" + "' information.'"+n,newLine+"+Actions WHERE [Status] ='Active'");
               cmd.ExecuteNonQuery();





我尝试了很多代码,但它不起作用。我想在行动之间加上一条新线。可能吗?



例如,在列中,它显示用户删除了'Cruz'信息。用户删除了'Reyes'信息。但我希望它是:

用户删除了'Cruz'信息。

用户删除了'Reyes'信息。



我尝试了什么:



我试过了\\\\ n和Environment.Newline但它也不起作用。



I have tried a lot of codes but it doesn't work. I want to put a new line between 'Actions'. Is it possible?

For example in the column , it shows "The user deleted 'Cruz' information. The user deleted 'Reyes' information." but i want it to be:
"The user deleted 'Cruz' information."
"The user deleted 'Reyes' information."

What I have tried:

I have tried \r\n and Environment.Newline but it doesn't work also.

推荐答案

见这里: c# - DataGridView单元格中的多行 - Stack Overflow [ ^ ]



[edit]

为了便于阅读,它仍然显示为一句话:(



啊。你没有按照链接然后...

Dropbox - WorksForMe.jpg [ ^ ]



生成的代码:

See here: c# - Multiple lines in a DataGridView cell - Stack Overflow[^]

[edit]
"For readability, it still shows as one sentence :("

Ah. You didn't follow the link then...
Dropbox - WorksForMe.jpg[^]

The code that generated that:
dgvDisplay.Columns["Actions"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dgvDisplay.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
dgvDisplay.Rows.Add("Teacher", "The user restored 'asdw' information.\nThe user restored 'o' information.\nThe user deleted 'eweewew' information.");



[\ edit]


[\edit]


这篇关于如何在datagridview中添加新行?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆