How to make a datagridview cell wrap?

In a window application I have the code below where Note is a column in the gridview grdNote.  I want to show the text in the Note column wrapped:

                    grdNote.DataSource = Nothing
                    Dim lobjNotes As New CNotes

                    With lobjNotes
                        .GetNotesByEmployerID(fobjEmployer.EmployerID)
                        If .Count > 0 Then
                            grdNote.AutoGenerateColumns = False
                            grdNote.DataSource = lobjNotes

                            grdNote.Columns(1).HeaderCell.SortGlyphDirection = SortOrder.Ascending
                        End If
                    End With
SillySoumareAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Wayne Taylor (webtubbs)Commented:
You'll need to use a few methods to achieve proper cell wrap, with row resize....

        With DataGridView1.Columns(0)
            .Width = 80
            .DefaultCellStyle.WrapMode = DataGridViewTriState.True
        End With

Then use the CellPainting Event to resize the row....

    Private Sub DataGridView1_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles DataGridView1.CellPainting
        If e.RowIndex < 0 Then Exit Sub
        DataGridView1.AutoResizeRow(e.RowIndex, DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
    End Sub

Wayne
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
SillySoumareAuthor Commented:
When I drag the row to expand it nothing happens.  It does not expand at all.
0
Wayne Taylor (webtubbs)Commented:
what do you mean "drag the row"?? Once you've entered data, it will increase the height itself.
0
Upgrade your Question Security!

Your question, your audience. Choose who sees your identity—and your question—with question security.

SillySoumareAuthor Commented:
When the form loads, the grid is already filled with data.  I would like to be able to drag the row downward to expand the cells so I can see all the data inside.  But what happens is when I drag it only expand but the data does not expand in the entire cell.  
0
Wayne Taylor (webtubbs)Commented:
>>When the form loads, the grid is already filled with data.

That's what my test was doing, and using the code I provided above, the row was automatically heightened ("expanded").
0
SillySoumareAuthor Commented:
Here is my code and it still does not work:
========================GetNote Routine:=======================
     grdNote.DataSource = Nothing
                    Dim lobjNotes As New CNotes

                    With lobjNotes
                        .GetNotesByEmployerID(fobjEmployer.EmployerID)
                        If .Count > 0 Then
                            grdNote.AutoGenerateColumns = False
                            grdNote.DataSource = lobjNotes
                            grdNote.Columns(4).DefaultCellStyle.WrapMode = DataGridViewTriState.True
                            grdNote.Columns(1).HeaderCell.SortGlyphDirection = SortOrder.Ascending
                        End If
                    End With

                    If Not (lobjNotes Is Nothing) Then lobjNotes = Nothing
========================Note Cell Painting Routine:=======================
  Private Sub grdNote_CellPainting(ByVal sender As Object, ByVal e As System.Windows.Forms.DataGridViewCellPaintingEventArgs) Handles grdNote.CellPainting
        Try
            If e.RowIndex < 0 Then
                Exit Sub
            Else
                grdNote.AutoResizeRow(e.RowIndex, DataGridViewAutoSizeRowMode.AllCellsExceptHeader)
            End If
        Catch ex As Exception

        End Try
    End Sub
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
.NET Programming

From novice to tech pro — start learning today.