|
web
newsgroups
|
|||||||||||||||||||||||
|
|||||||||||||||||||||||
Refreshing datagridview after a rowtemplate height changeHi 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 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights. Hi Jeffrey
Thanks for the reply, works a treat regards Steve ""Jeffrey Tan[MSFT]"" <je***@online.microsoft.com> wrote in message Show quoteHide quote news:dJbPYQuqGHA.6120@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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. > ================================================== > This posting is provided "AS IS" with no warranties, and confers no > rights. > 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/subscriptions/managednewsgroups/default.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/subscriptions/support/default.aspx. ================================================== This posting is provided "AS IS" with no warranties, and confers no rights.
Public Shared Property
Barcode scanning concurrency question String comparison algorithms ByRef - delayed update of the original variable? The RPC Server is unavailable! Moving toolbox How to Automate Calls to a Web Site with Different Parameters on the URL capture records Affected count from dataAdapter.Update(...? Editing Data |
|||||||||||||||||||||||