4

Im using c# .net windows form application. i have a datagrid view. It has two columns.I need to make all the cells on the second column as to have multiple line. i.e a multiline column. I will edit something in a cell and press enter key. the cursor should reach the next line in the same cell. It should not go to the next cell. What should i do?

H H
  • 263,252
  • 30
  • 330
  • 514
saeed
  • 673
  • 3
  • 12
  • 22

1 Answers1

5

If you set the column default style like:

this.dataGridView1.Columns[index].DefaultCellStyle.WrapMode = DataGridViewTriState.True;

you can enter multiline by pressing SHIFT-ENTER

Otherwise you could change the cell control editor overriding dataGridView or handling EditingControlShowing event (the default control is a textbox)

EDIT: there's almost the same question here: DataGridView: How can I make the enter key add a new line instead of changing the current cell?

Community
  • 1
  • 1
digEmAll
  • 56,430
  • 9
  • 115
  • 140
  • Thanks a lot. Its Working fine. But only for shift-enter.. If i press Only enter, it is going to next row. Any alternative that can allow me to use only enter key. – saeed Apr 19 '10 at 12:00
  • Take a look at the last answer in the link posted above. It seems to work. – digEmAll Apr 19 '10 at 12:24