Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

Multiple lines in a cell in a datagrid view

Tags:

c#

winforms

I'm using C# .net.. in that I'm working with windows form application

I have a datagrid view with two columns. the first column is readonly and the other is editable. now I want every cell of the second column to support for multilines in each cell. I want to press enter key and come to the next line in the same cell. But now if I press enter key it is going to the next cell below it. I want the cursor to be in the next line of the same cell

like image 276
saeed Avatar asked Nov 06 '22 14:11

saeed


1 Answers

Maybe you can:

  1. hook to the KeyDown event
  2. check if Enter was hit, if true:
  3. add a linebreak to the cell's string value, and:
  4. mark the event has handled by setting e.SuppressKeyPress to True
like image 183
M.A. Hanin Avatar answered Nov 15 '22 07:11

M.A. Hanin