1

So when I add something in my datagridview the newline function doesnt work but it works in messagebox

Newline function tried: Environment.NewLine, vbCr, vbCrLf and vbLf

My Input: 7 : 30 AM 8 : 30 AM

and my code is:

sched1a = "7:30" schedformat1a = "AM" sched2a = "7:30" schedformat2a = "AM"

MsgBox(dgv.Rows(rcount).Cells(0).Value)
    rcount = dgv.RowCount - 1
    dgv.Rows.Add()
    dgv.Rows(rcount).Cells(0).Value = sched1a.Text & schedformat1a.Text & Environment.NewLine & sched2a.Text & schedformat2a.Text

Even when adding the height and width. The newline function still doesnt work. Is there a possible way to do this? Thanks!

HazzoN
  • 56
  • 1
  • 9
  • Hi HazzoN, couple things: 1. What is the type of the cell at `Cells(0)`, is it a [DataGridViewTextBoxCell](https://msdn.microsoft.com/en-us/library/system.windows.forms.datagridviewtextboxcell%28v=vs.110%29.aspx)? 2. It looks like your code was not formatted properly, you might want to [edit your question](https://stackoverflow.com/posts/47542665/edit). 3. I recommend editing your title a bit, to make it clear if you are looking to have a multi-line text cell; as of right now it also sort of sounds like you just want an empty DataGridView row. – jrh Nov 28 '17 at 23:34
  • `NewLine` is not a function. It is a property. To enable multi line text, you need to set the `WrapMode` (property) of the `DefaultCellStyle` for that column. – Ňɏssa Pøngjǣrdenlarp Nov 28 '17 at 23:35
  • @Jimi While I agree with you, it seems like the consensus [on meta](https://meta.stackoverflow.com/a/348797/4975230t) is to not allow cross language duplicates, even though the .NET framework is the same, please consider voting on that post. – jrh Nov 28 '17 at 23:37
  • Im sorry for having no knowledge about NewLine and i've just solve the problem thanks to you Sir's the Wrap Mode worked for me – HazzoN Nov 28 '17 at 23:38

0 Answers0