locked
Spare Row at the botton of the DGV RRS feed

  • Question

  • Hi All

    Whenever I bind Data to the DGV control, there always seems to be a small grey area at the bottom of the control that I can't get rid off, no matter how carefully I size the control at design time. I am using the AutoSizeMode property of the right hand column to ensure there is no 'spare space' horizontally when the control/form is resized, but I can't find any similair property to get rid of the spare vertical space.

    I thought it may be due to the control leaving room for a user to add a new row of data, or for scroll bars, but whatever I seem to do, theres always a small bit of space after by rows. I have now set the background colour of the grid from the dark grey default to something less in your face, but this is only a work around IMHO.

     

    Friday, October 13, 2006 3:09 PM

Answers

  • Maybe try something like this

     


    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.AllowUserToAddRows = False
            DataGridView1.Columns.Add("Test", "Test")
            DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            DataGridView1.Rows.Add("1")
            DataGridView1.Rows.Add("2")
            DataGridView1.Rows.Add("3")
            Dim r As Rectangle = DataGridView1.GetRowDisplayRectangle(DataGridView1.RowCount - 1, False)
            DataGridView1.Height = r.Bottom + 1
        End Sub
    End Class

     

    Saturday, October 14, 2006 5:56 PM

All replies

  • Maybe try something like this

     


    Public Class Form1
        Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
            DataGridView1.AllowUserToAddRows = False
            DataGridView1.Columns.Add("Test", "Test")
            DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
            DataGridView1.Rows.Add("1")
            DataGridView1.Rows.Add("2")
            DataGridView1.Rows.Add("3")
            Dim r As Rectangle = DataGridView1.GetRowDisplayRectangle(DataGridView1.RowCount - 1, False)
            DataGridView1.Height = r.Bottom + 1
        End Sub
    End Class

     

    Saturday, October 14, 2006 5:56 PM
  • Hi

    I had previously tried something similair, but you got me pointing in the right direction. Eventually came up with the following to do what I was looking for.

    Private Sub Form1_ResizeEnd(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.ResizeEnd

    Dim intFullRows As Integer

    intFullRows = DataGridView1.DisplayedRowCount(False) + 1

    DataGridView1.Height = intFullRows * DataGridView1.Rows(1).Height - 1

    End Sub

    Thanks for your time looking into this.

     

     

     

    Monday, October 16, 2006 7:44 AM