Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.4k views
in Technique[技术] by (71.8m points)

vb.net - Datagridview multi line textbox when ctrl+enter press

I'm trying to add some specific behavior to a datagridview control (if you can put it like that).

I would like to have a multiplelines textbox control in the datagridview. I achieved this when giving a string that is too long to fit in the textbox, it's automatic placed on a second line.

So the steps would be enter text into a cell, while the focus is on the cell press ctrl+enter so that the text entered next is on a second line.

dataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True
dataGridView1.AutoSizeRowsMode = DataGridViewAutoSizeRowsMode.AllCells

But I would also be able to force a second line by pressing ctrl + enter key On this matter my internet search came up empty.

I guess it would be catching the key press event within a cell but I can't seem to find this event.

Possible events

I tried this event, but it only happens when the Datagridview in total is selected.

Private Sub DataGridView1_CellContentClick(sender As Object, e As System.Windows.Forms.KeyPressEventArgs) Handles DataGridView1.KeyPress
     ' Some magic here.
End Sub
See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I am fairly confident you can achieve the desired results by changing a couple of properties in the DataGridView and use a “Shift-Enter” instead of “Ctrl-Enter”.

In the DataGridView set its AutoSizeRowsMode to AllCells, then set the particular COLUMNS DefaultCellStyle -> WrapMode to true. Then use a “Shift-Enter” while editing a cell and you should get multiple lines in a cell. Hope this is what you were looking for.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...