按住Ctrl + Enter时的Datagridview多行文本框 [英] Datagridview multi line textbox when ctrl+enter press
问题描述
我正在尝试向datagridview
控件添加一些特定的行为(如果可以这样表示的话).
I'm trying to add some specific behavior to a datagridview
control (if you can put it like that).
我想在datagridview
中有一个multiplelines
textbox
控件.当给出的字符串太长而无法放入textbox
时,我实现了这一点,它会自动放在第二行.
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.
因此,步骤是在单元格中输入文本,同时将焦点放在该单元格上,按ctrl + enter,以使下一个输入的文本在第二行上.
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
但是我也可以通过按ctrl + enter key
来强制第二行.在这个问题上,我的互联网搜索空了.
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.
我尝试了此事件,但是只有在总共选择了Datagridview
时,它才会发生.
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
推荐答案
我非常有信心您可以通过更改DataGridView
中的几个属性并使用"Shift-Enter"而不是"Ctrl"来获得所需的结果. -Enter".
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".
在DataGridView
中将其AutoSizeRowsMode
设置为AllCells
,然后将特定的COLUMNS DefaultCellType
-> WrapMode
设置为true.然后在编辑单元格时使用"Shift-Enter",您应该在一个单元格中获得多行.希望这就是您想要的.
In the DataGridView
set its AutoSizeRowsMode
to AllCells
, then set the particular COLUMNS DefaultCellType
-> 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.
这篇关于按住Ctrl + Enter时的Datagridview多行文本框的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!