dcsimg
Results 1 to 3 of 3
  1. #1

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    11

    Resolved [RESOLVED] datagridview row height according to string lines

    i have a datagridview with 2 columns and several rows . some rows are supplied with multi-line strings like this :

    Code:
    dim rowcontent as string = "test" & vbnewline & "test
    
     Dim row As String() = New String() {"content", rowcontent}
            DataGridView1.Rows.Add(row)
    i checked settings of datagridview , autosize properties and ... , i didn't find what I want. I need the rows to adjust their height according to their content lines.

    anyone knows ?

  2. #2
    Frenzied Member ChrisE's Avatar
    Join Date
    Jun 2017
    Location
    Frankfurt
    Posts
    1,063

    Re: datagridview row height according to string lines

    Hi,

    try this...
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add("Sp1", "SP1")
                Dim i As Integer = .Columns.Add("Sp2", "SP2")
                .Columns(i).DefaultCellStyle.WrapMode = DataGridViewTriState.True
                .Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Rows.Add(10)
            End With
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            With DataGridView1
                .Rows(5).Cells(1).Value = "Sunday 25.02.2018"
                Dim Gr As Graphics = Me.CreateGraphics()
                .Rows(5).Height = Gr.MeasureString("x", .Font).Height * 2 + 2
            End With
        End Sub
    End Class
    regards
    Chris
    to hunt a species to extinction is not logical !
    since 2010 the number of Tigers are rising again in 2016 - 3900 were counted. with Baby Callas it's 3901, my wife and I had 2-3 months the privilege of raising a Baby Tiger.

  3. #3

    Thread Starter
    New Member
    Join Date
    Feb 2018
    Posts
    11

    Re: datagridview row height according to string lines

    Quote Originally Posted by ChrisE View Post
    Hi,

    try this...
    Code:
    Public Class Form1
    
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            With DataGridView1
                .Columns.Add("Sp1", "SP1")
                Dim i As Integer = .Columns.Add("Sp2", "SP2")
                .Columns(i).DefaultCellStyle.WrapMode = DataGridViewTriState.True
                .Columns(i).DefaultCellStyle.Alignment = DataGridViewContentAlignment.MiddleCenter
                .Rows.Add(10)
            End With
        End Sub
    
        Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles Button1.Click
            With DataGridView1
                .Rows(5).Cells(1).Value = "Sunday 25.02.2018"
                Dim Gr As Graphics = Me.CreateGraphics()
                .Rows(5).Height = Gr.MeasureString("x", .Font).Height * 2 + 2
            End With
        End Sub
    End Class
    regards
    Chris
    Thanks a lot

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Featured


Click Here to Expand Forum to Full Width


×
We have made updates to our Privacy Policy to reflect the implementation of the General Data Protection Regulation.