473,399 Members | 2,858 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,399 software developers and data experts.

Refreshing datagridview after a rowtemplate height change

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
3 9419
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
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
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Spam Catcher | last post by:
Is it possible to fix the row height of a data grid view row? Thanks!
1
by: romerve | last post by:
Hello; i am having some problems trying to get a form that has a datagridview to refresh after a new record is created. I have a MDI container and menu form and add new record form; the menu...
4
by: Vidhura | last post by:
This article explains how to make all the rows height the same in DataGridView in .Net 2.0 while using AutoSizeRowMode In DataGridView 2.0,there is a option to resize row to fit the content of...
1
by: Jeff | last post by:
Hey ..NET 2.0 I've created a User Control which contain a DataGridView. This User Control is displayed on a TabPage. This TabPage is added to the TabControl during runtime. The problem is...
1
by: Tom | last post by:
First, I posted a similar request for help in another group and now don't find the posting. Problem with my newsreader perhaps ... but apologies if this appears as a cross posting. My code is...
1
by: gleave | last post by:
Hi, below is the code i got to print a datagridview, the trouble is it also prints visible columns which i don't want to be printed. Does anyone have any ideas on how i could change the code so it...
5
by: =?Utf-8?B?bWljaGFlbCBzb3JlbnM=?= | last post by:
I want to be able to increase or decrease row heights of a populated DataGridView from the keyboard. I set up a test program with menu items to increase and decrease, assigned shortkey keys...
1
by: Andrus | last post by:
I have Winforms DataGridView whose DataSource Rids is Marc sample TableListCollection<TRowderived from BindingList. It is used to edit invoice rows. If user presses Revert button, my application...
1
by: sridhar kumar | last post by:
how to change the colur of datagridview control column and rows
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.