Refreshing datagridview after a rowtemplate height change

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • steve

    Refreshing datagridview after a rowtemplate height change

    Hi All

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

    I have tried datagridview1.r efresh 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


  • Jeffrey Tan[MSFT]

    #2
    RE: Refreshing datagridview after a rowtemplate height change

    Hi Steve,

    Thanks for your post!

    Yes, DataGridView.Ro wTemplate property is used for the default row template
    of new created rows. So if you change the DataGridView.Ro wTemplate 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.Ro wTemplate value.

    Below is the sample code demonstrates my statement:

    Public Class Form1

    Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button1.Click

    Me.DataGridView 1.RowTemplate.H eight =
    Me.DataGridView 1.RowTemplate.H eight + 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(ByVa l sender As System.Object, ByVal e As
    System.EventArg s) 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.DataGridView 1.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.Ro ws collection to get each DataGridViewRow reference and
    change its Height property. The code snippet below demonstrate this:

    Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
    System.EventArg s) Handles Button2.Click
    Dim i As Integer
    Dim dgvr As DataGridViewRow
    For i = 0 To Me.DataGridView 1.Rows.Count - 1
    dgvr = Me.DataGridView 1.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
    Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

    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.

    Comment

    • steve

      #3
      Re: Refreshing datagridview after a rowtemplate height change

      Hi Jeffrey

      Thanks for the reply, works a treat


      regards
      Steve

      ""Jeffrey Tan[MSFT]"" <jetan@online.m icrosoft.comwro te in message
      news:dJbPYQuqGH A.6120@TK2MSFTN GXA01.phx.gbl.. .
      Hi Steve,
      >
      Thanks for your post!
      >
      Yes, DataGridView.Ro wTemplate property is used for the default row
      template
      of new created rows. So if you change the DataGridView.Ro wTemplate
      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.Ro wTemplate value.
      >
      Below is the sample code demonstrates my statement:
      >
      Public Class Form1
      >
      Private Sub Button1_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button1.Click
      >
      Me.DataGridView 1.RowTemplate.H eight =
      Me.DataGridView 1.RowTemplate.H eight + 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(ByVa l sender As System.Object, ByVal e As
      System.EventArg s) 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.DataGridView 1.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.Ro ws collection to get each DataGridViewRow reference and
      change its Height property. The code snippet below demonstrate this:
      >
      Private Sub Button2_Click(B yVal sender As System.Object, ByVal e As
      System.EventArg s) Handles Button2.Click
      Dim i As Integer
      Dim dgvr As DataGridViewRow
      For i = 0 To Me.DataGridView 1.Rows.Count - 1
      dgvr = Me.DataGridView 1.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
      Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

      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.
      >

      Comment

      • Jeffrey Tan[MSFT]

        #4
        Re: Refreshing datagridview after a rowtemplate height change

        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
        Find official documentation, practical know-how, and expert guidance for builders working and troubleshooting in Microsoft products.

        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.

        Comment

        Working...