473,385 Members | 1,893 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,385 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 9416
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: aa123db | last post by:
Variable and constants Use var or let for variables and const fror constants. Var foo ='bar'; Let foo ='bar';const baz ='bar'; Functions function $name$ ($parameters$) { } ...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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
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
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,...

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.