-
Feb 25th, 2018, 12:43 AM
#1
Thread Starter
New Member
[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 ?
-
Feb 25th, 2018, 01:25 AM
#2
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.
-
Feb 25th, 2018, 08:17 AM
#3
Thread Starter
New Member
Re: datagridview row height according to string lines
Originally Posted by ChrisE
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
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|