cobolinx1
asked on
hitting the enter button in datagridviewtextcell
I want to be able to hit the enter button in a datagridviewtextcell and have it create a new line within the cell and autoformat the size of the cell. How would I do that?
ASKER
Is there a way to capture the keystroke in the cell and if its the enter button make the cell values = cellvalue & vbnewline?
yes you can ....
use Editing Control Showing event like this
use Editing Control Showing event like this
Private WithEvents thiscontrol As TextBox
Private Sub MyDataGridView_EditingControlShowing(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewEditingControlShowingEventArgs) Handles MyDataGridView.EditingControlShowing
Try
If MYDataGridView.CurrentCell.ColumnIndex = "YOURCOLUMNINDEX" Then
thiscontrol = CType(e.Control, TextBox)
Else
thiscontrol = Nothing
End If
Private Sub thiscontrol_KeyDown(ByVal sender As Object, ByVal e As System.Windows.Forms.KeyEventArgs) Handles thiscontrol.KeyDown
If e.KeyCode = Keys.Return Then
.....WHAT YOU WANT.....
End Sub
ASKER
Nope it interprets the enter key as moving to the next row before it can fire off the keydowncode
think...... then how do you move FROM the cell if the enter key is "escaped" to a vbnewline?
(Actually, I am surprised that you can do a vbnewline in a datagridviewcell, but then again, something new a day, not bad.)
(Actually, I am surprised that you can do a vbnewline in a datagridviewcell, but then again, something new a day, not bad.)
ASKER
...I would actually be mouse clicking off it and when it lost focus Id create a new line in the datagridview.. I guess I could have the user type in a textbox and when they click a button they could add it to the datagridview...no other way though??
mmm...so you need a multiline textbox????
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
ASKER
I would have to capture the keydown before the cellendedit and then then try to set the cursor back. I think I'll just have them hit shift and enter. Thanks.
To autoresize the cell, call an autoresize routine from the CellEndEdit.
I am not sure you can create a new line in a cell if that is what you want.