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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Wayne Taylor (webtubbs)Connect With a Mentor AstronautCommented:
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
 
SillySoumareAuthor Commented:
When I drag the row to expand it nothing happens.  It does not expand at all.
0
 
Wayne Taylor (webtubbs)AstronautCommented:
what do you mean "drag the row"?? Once you've entered data, it will increase the height itself.
0
The new generation of project management tools

With monday.com’s project management tool, you can see what everyone on your team is working in a single glance. Its intuitive dashboards are customizable, so you can create systems that work for you.

 
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)AstronautCommented:
>>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
All Courses

From novice to tech pro — start learning today.