按住Ctrl + Enter时的Datagridview多行文本框 [英] Datagridview multi line textbox when ctrl+enter press

查看:113
本文介绍了按住Ctrl + Enter时的Datagridview多行文本框的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在尝试向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屋!

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