datagridview - multi-line input cell?

Cecilia

Member
Joined
Aug 14, 2007
Messages
24
Programming Experience
Beginner
The DataGridView is for data entry, the data are strings, which could be short or long. I could set the wrapmode to make the text wrap in the cell, but I also want to put the cursor at the beginning of a new line (in the same cell) if I hit "ENTER". But with DataGridView, when you hit "enter", it goes to next cell, if you hit "shift+enter" it does what I need it to do. I googled a lot, some show me how to ignore the "enter" while editing, but still don't know how to make a multi-line input cell. Anyone could help? Thanks!
 
  1. To display multiline text in DgvTextbox set WrapMode=True for the columns DefaultsCellStyle. (defaults to displaying rectangles for linefeed chars)
  2. The row Height can be modified for the DGVs RowTemplate.
  3. To insert linefeed when editing the text in a cell press the key combination Shift-Enter.
This is how I fixed the initial row problem, there may be other solutions too:
VB.NET:
Me.DataGridView1.Rows(0).Height = Me.DataGridView1.RowTemplate.Height
 
Thanks JohnH,
I use
With Me.DataGridView1.DefaultCellStyle.WrapMode = DataGridViewTriState.True

It won't work.
 
What I did was to use the designer dialog for configuring the columns. It works for me also when setting this in designer for DefaultCellStyle of the DataGridView control itself, it will be a value used for all columns if not overridden. The only code I wrote when testing this was the one line in previous post. When I use code such as what you indicated instead of using the visual tools I find that this also works for me. Was it the "With" keyword that gave you problems?
 
My bad

Thanks JohnH. The "with" shouldn't be there, mistake from copy & paste. The real problem is when I test the wrapmode, I type in a random string like "fdafddsfdfsd" without a space, so it is treated as a single word, so no wrapping. My bad, sorry!
 
From this post i have some questions:

can i really change the internal keys of datagridview,can i go to any cell and start editing by pressing 'Enter' button....

and can anyone explain me wht warp mode is
 
Just in case somebody else looking into this.
After we added a new row, perhaps you would want to include:
someDGV.autoResizeRows()
 
Back
Top