[英]Preventing a new row from appearing in a DataGridView before current row is filled in?
[英]WinForm wrap text if current row width is filled
我在WinForm中有DataGridView。 我將AutoSizeColumnsMode
設置為Fill
,因為如果用戶調整窗口大小,我不需要空格。
我想要實現的目標。 例如,用戶在特定單元格中鍵入一些文本。 當文本寬度變為單元格寬度時,文本必須是新行的一個。
怎么樣:
|Cell Header|
-------------
|text-text |
和
|Cell Header|
-------------
|text-text |
|more text |
|on the new |
|line |
我的列可由用戶調整大小。 所以這:
|Cell Header|
-------------
|text-text |
|more text |
|on the new |
|line |
可能會這樣:
|Cell Header |
---------------------
|text-text more text|
|on the new line |
我從其他SO答案中嘗試過:
AutoResizeRowsMode
設置為AllCells
- 沒有幫助 DefaultCellStyle.WrapMode
設置為True
- ddin't help 我怎么能實現這個呢?
編輯:列設置:
編輯#2:
除了為列設置包裝模式和自動大小模式之外,還需要為行設置大小模式。
public class Model
{
public int Id { get; set; }
public string Text { get; set; }
}
private void Form1_Load(object sender, EventArgs e)
{
var list = new List<Model>
{
new Model{Id = 1, Text = "Lorem ipsum" },
new Model{Id = 2, Text = "Lorem ipsum dolor sit amet." },
new Model{Id = 3, Text = "Lorem ipsum dolor sit amet, consectetur adipiscing elit." },
};
dataGridView1.DataSource = list;
dataGridView1.Columns["Text"].AutoSizeMode = DataGridViewAutoSizeColumnMode.Fill;
dataGridView1.Columns["Text"].DefaultCellStyle.WrapMode = DataGridViewTriState.True;
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells;
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.