By using this site, you agree to our updated Privacy Policy and our Terms of Use. Manage your Cookies Settings.
448,691 Members | 1,123 Online
Bytes IT Community
+ Ask a Question
Need help? Post your question and get tips & solutions from a community of 448,691 IT Pros & Developers. It's quick & easy.

Refreshing datagridview after a rowtemplate height change

P: n/a
Hi All

How can I get the datagridview to redraw after changing the
rowtemplate.height at runtime ( it is databound to a datatable)

I have tried datagridview1.refresh etc to no avail (The row height stays the
same)

If I repopulate its datasource (datatable) then the rows resize OK, but that
is an uneccessary overhead.

Regards
Steve
Jul 18 '06 #1
Share this Question
Share on Google+
3 Replies


P: n/a
Hi Steve,

Thanks for your post!

Yes, DataGridView.RowTemplate property is used for the default row template
of new created rows. So if you change the DataGridView.RowTemplate property
before the DataGridView is bound, DataGridView will use this modified value
to display the rows. However, if you change this property after the all the
rows are created, its modification will not reflect on existing rows. If
you add a new row into the DataGridView, the new row will reflect this new
DataGridView.RowTemplate value.

Below is the sample code demonstrates my statement:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.DataGridView1.RowTemplate.Height =
Me.DataGridView1.RowTemplate.Height + 10
Dim dr As DataRow
dr = dt.NewRow()
dr("column1") = 100
dr("column2") = "item100"
dt.Rows.Add(dr)
End Sub

Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

dt.Columns.Add("column1", GetType(Integer))
dt.Columns.Add("column2", GetType(String))

Dim i As Integer
Dim dr As DataRow
For i = 0 To 5
dr = dt.NewRow()
dr("column1") = i
dr("column2") = "item" + i.ToString()
dt.Rows.Add(dr)
Next
Me.DataGridView1.DataSource = dt
End Sub
End Class

If you click the Button1, the new added row will be 10 pixel heigher than
original rows.

To change the existing rows height, you should enumerate through the
DataGridView.Rows collection to get each DataGridViewRow reference and
change its Height property. The code snippet below demonstrate this:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim dgvr As DataGridViewRow
For i = 0 To Me.DataGridView1.Rows.Count - 1
dgvr = Me.DataGridView1.Rows(i)
dgvr.Height = dgvr.Height + 10
Next
End Sub

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 19 '06 #2

P: n/a
Hi Jeffrey

Thanks for the reply, works a treat
regards
Steve

""Jeffrey Tan[MSFT]"" <je***@online.microsoft.comwrote in message
news:dJ**************@TK2MSFTNGXA01.phx.gbl...
Hi Steve,

Thanks for your post!

Yes, DataGridView.RowTemplate property is used for the default row
template
of new created rows. So if you change the DataGridView.RowTemplate
property
before the DataGridView is bound, DataGridView will use this modified
value
to display the rows. However, if you change this property after the all
the
rows are created, its modification will not reflect on existing rows. If
you add a new row into the DataGridView, the new row will reflect this new
DataGridView.RowTemplate value.

Below is the sample code demonstrates my statement:

Public Class Form1

Private Sub Button1_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button1.Click

Me.DataGridView1.RowTemplate.Height =
Me.DataGridView1.RowTemplate.Height + 10
Dim dr As DataRow
dr = dt.NewRow()
dr("column1") = 100
dr("column2") = "item100"
dt.Rows.Add(dr)
End Sub

Dim dt As New DataTable
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles MyBase.Load

dt.Columns.Add("column1", GetType(Integer))
dt.Columns.Add("column2", GetType(String))

Dim i As Integer
Dim dr As DataRow
For i = 0 To 5
dr = dt.NewRow()
dr("column1") = i
dr("column2") = "item" + i.ToString()
dt.Rows.Add(dr)
Next
Me.DataGridView1.DataSource = dt
End Sub
End Class

If you click the Button1, the new added row will be 10 pixel heigher than
original rows.

To change the existing rows height, you should enumerate through the
DataGridView.Rows collection to get each DataGridViewRow reference and
change its Height property. The code snippet below demonstrate this:

Private Sub Button2_Click(ByVal sender As System.Object, ByVal e As
System.EventArgs) Handles Button2.Click
Dim i As Integer
Dim dgvr As DataGridViewRow
For i = 0 To Me.DataGridView1.Rows.Count - 1
dgvr = Me.DataGridView1.Rows(i)
dgvr.Height = dgvr.Height + 10
Next
End Sub

Hope this helps!

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no
rights.

Jul 19 '06 #3

P: n/a
Ok, if you need further help, please feel free to post. Thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
==================================================
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
==================================================
This posting is provided "AS IS" with no warranties, and confers no rights.

Jul 19 '06 #4

This discussion thread is closed

Replies have been disabled for this discussion.