[RESOLVED] Adding a new line into a cell of a DataGridView
Hello.
I have searched for this, and not been able to find any examples where someone has done this. I'm trying to add a new line into the cell of a DataGridView so the text appears on 2 lines (of the same cell). Here's some code to explain what i'm doing:
Code:
Dim DS As New DataSet("aa")
Dim tbl As DataTable = DS.Tables.Add("bb")
Dim xRow2 As DataRow = tbl.NewRow()
xRow2("Equipment") = "-Lawnmower" & vbCrLf & "-Logcutter"
tbl.Rows.Add(xRow2)
grdRented.DataSource = DS.Tables("bb")
But the entries keep showing up on the same line with an unknown character code (ie: -Lawnmower[]-Logcutter) instead of being on two separate lines. How can i make it bump the text down a line (inside the cell) so that it appears like this?:
-Lawnmower
-Logcutter
I've seen this code done (and work) in VB6 with a grid control, so i'm confused as to why i can't get it to work now. Am i missing some super top secret setting that allows it to span two lines?
.
Last edited by MrGTI; Oct 11th, 2011 at 09:41 AM.
Reason: resolved
Re: Adding a new line into a cell of a DataGridView
See attached VS2008 project where the second column does wrapping. Some of the properties are set in the DataGridView property window and one is set in the last line of the Load event of the form.
All i needed to do was to turn on the ability for the DataGridView to allow text to wrap. Once i added that, it worked. Thanks for your help!
.
Good to hear this worked. In regards to vbCrLf vs Environment.NewLine, NewLine is a constant customized specifically for the current platform and implementation of the .NET Framework as per MSDN page so if you are fine with vbCrLf so be it. Indeed DefaultCellStyle.WrapMode = DataGridViewTriState.True was what you needed :-)