Click here to Skip to main content
15,889,216 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
hi,

i have a data grid view in which one of the cell contains "wrapping =true" when i enter long text the text goes to the next line in the same cell, but when we press enter key it enters into next cell but not to the next line in the same cell...

can you please help me to resolve this...
when i entered into a cell and enter a text and i want another text to be entered in next line of the same cell.. by pressing enter...


thanks in advance...
Posted
Comments
Sergey Alexandrovich Kryukov 3-Jun-15 1:57am    
What's wrong with reading original MSDN documentation?
—SA

use dataGridView KeyDown event and check for e.KeyData == Keys.Enter then you can check the dataGridView CurrentCell column and row index to calculate next cell column index and row index. finally set the dataGridView1.CurrentCell value using that cell. for example check below answer
DataGridView-when I press enter it goes to the next cell[^]
How to move focus on next cell in a datagridview on Enter key press event[^]
 
Share this answer
 
First, the selection mode should be System.Windows.Forms.DataGridViewSelectionMode.CellSelect:
https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.selectionmode%28v=vs.110%29.aspx[^],
https://msdn.microsoft.com/en-us/library/3c89df86%28v=vs.110%29.aspx[^].

And then, this is how you select a cell: https://msdn.microsoft.com/en-us/library/yc4fsbf5%28v=vs.90%29.aspx[^].

And this is how you can handle keyboard events to act on Enter: https://msdn.microsoft.com/en-us/library/system.windows.forms.control.keydown(v=vs.110).aspx[^].

That's all.

—SA
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900