none
How can I set the distance from last row to the end of datagridview ?

    Question

  • Hi,
    How can I set the distance from last row to the end of datagridview ?
    My last row stay at the end of datagridview ,  so i want to have last row at the top of the datagridview ,
    and I want increase the distance between last row and the end of datagridview .


    Friday, May 06, 2016 12:08 PM

Answers

  • I want scroll last row to top of datagridview

    I can do that with panel by AutoScrollMargin
    but with datagridview I can't .

    The DataGridView has a specific clientsize for displaying the DataGridView rows and columns which works in conjunction with the DataGridView displaying scrollbars. The DataGridView appears to only be designed for using scrollbars when the clientsize is too small to for the entired display requirement for the DataGridView.

    Plus the DataGridView scrolling always displays the Columns regardless of the Rows.

    So I placed a DataGridView on a Form and set the ClientSize much larger than what the control actuall displays. This stops the Vertical ScrollBar from displaying though.

    I did not use a VScrollBar with the app. The VScrollBar never reaches its max value because the slider is not taken into account due to the sliders height for whatever reason. You could write code that correctly sets a max value for a VScrollBar such that the max value adds how much is required to get the desired max value in the VScrollBar that you want it to be able to scroll to but I didn't do that here.

    Also if you update the DGV so it has new rows added to it or a new table is bound to it or something that causes its ClientSize to need to be altered to accomodate that then you will need to use appropriate events and appropriate code from the below code to update necessary values.

    I used a TrackBar set to Vertical. The TrackBar thumb normally sits at the bottom of the TrackBar at value 0 when the TrackBar is set to vertical. You will note that I set the TrackBar to its max value in Form Load so that the slider button is at the top of the TrackBar.

    Also the retrieved TrackBar value is subtracted from the TrackBars max value so a 0 is provided when the TrackBar is at its max value and negative numbers are retrieved as the TrackBar moves down to 0. Math.Abs returns the absolute value of those equations which is a positive number.

    The DataGridView's Rows have their visibility set to False or True depending on the movement of the TrackBar. So the DataGridView isn't really scrolling but having rows hidden so other rows look like they are moving up and down.

    There is an issue with trying to set a rows visibility to False while the DataTables Currency Manager is in a DataGridView row if you are using a DataTable or possibly DataSet or something like that. Therefore the currency manager has to be moved somewhere so I just move it to the last row that contains data in the DataGridView.

    I also deselect everything which may not be necessary. I don't know if a selected row can have its visibility set to false and still be a selected item in DataGridViews Selected Rows or whatever.

    The DataGridView itself may function in this fashion for all I know in that as it's vertical scrollbar is used it hide/show rows. I have no idea. If that's true though then there may be all kinds of logic used by the DataGridView so it knows what rows, now not visible, are selected (if a non-visible row can not remain selected), etc. Although DataGridView probably just paints whatever it wants to display when the scrollbars are moved.

    If you anchor a DataGridView then you will need to use approriate events to reset values in necessary code to whatever the new values should be if the DataGridView resizes when the Form resizes if the anchors for the DGV resize it when that happens. Also if rows are added or deleted.

    In the test DGV the user was set to be allowed to add rows as the default which is why - 2 is used since the last row with data in it needs to be displayed. You could use an If or Select Case statement to determine if that value is true or false and set the other values appropriate.

    Option Strict On
    
    Public Class Form1
    
        WithEvents MultiVarAnalysis As New DataTable("SixSigma") ' Create DataTable with events.
        WithEvents MVASS As New BindingSource ' Create BindingSource with events.
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
    
            DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            DataGridView1.Anchor = CType(AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Top, AnchorStyles)
            DataGridView1.MultiSelect = False
            DataGridView1.AllowDrop = True
            DataGridView1.AutoSize = True
            DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    
            MultiVarAnalysis.Columns.Add("Shift", GetType(String)) ' Represents FA
            MultiVarAnalysis.Columns("Shift").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Hello this is a long column", GetType(String)) ' Represents FB
            MultiVarAnalysis.Columns("Hello this is a long column").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Hour", GetType(String)) ' Represents FC
            MultiVarAnalysis.Columns("Hour").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Unit", GetType(String)) ' Represents FD
            MultiVarAnalysis.Columns("Unit").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Output", GetType(Double)) ' Represents Y
            MultiVarAnalysis.Columns("Output").AllowDBNull = False
    
    
            ' Add rows to DataTable
    
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U1", 0.947)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U2", 5.427)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U3", 8.334)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U4", 4.637)
    
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U1", 4.766)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U2", 4.461)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U3", 5.791)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U4", 2.313)
    
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U1", 4.804)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U2", 5.238)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U3", 5.767)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U4", 5.108)
    
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U1", 3.829)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U2", 5.539)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U3", 8.18)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U4", 4.86)
    
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U1", 3.339)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U2", 8.978)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U3", 9.681)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U4", 3.86)
    
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U1", 2.816)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U2", 5.519)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U3", 7.321)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U4", 4.321)
    
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U1", 2.772)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U2", 7.431)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U3", 5.388)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U4", 6.911)
    
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U1", 3.5886)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U2", 8.043)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U3", 3.641)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U4", 5.306)
    
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U1", 3.929)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U2", 4.164)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U3", 8.427)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U4", 3.835)
    
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U1", 4.936)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U2", 8.874)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U3", 8.38)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U4", 5.214)
    
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U1", 4.059)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U2", 6.018)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U3", 4.035)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U4", 6.031)
    
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U1", 4.911)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U2", 8.189)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U3", 6.118)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U4", 6.3)
    
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U1", 2.834)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U2", 4.142)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U3", 12.935)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U4", 12.834)
    
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U1", 4.487)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U2", 9.328)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U3", 10.0245)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U4", 6.387)
    
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U1", 9.044)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U2", 6.322)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U3", 11.498)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U4", 7.943)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U5", 2.198)
    
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U1", 7.245)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U2", 13.918)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U3", 18.456)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U4", 11.925)
    
            MultiVarAnalysis.AcceptChanges()
            MVASS.DataSource = MultiVarAnalysis
            DataGridView1.DataSource = MVASS
    
            For i = 0 To DataGridView1.ColumnCount - 1
                DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.Automatic
            Next
    
            DataGridView1.ClientSize = New Size(DataGridView1.ClientRectangle.Width, CInt(DataGridView1.ColumnHeadersHeight + Math.Ceiling(DataGridView1.Rows.Count * DataGridView1.Rows(0).Height) + DataGridView1.ClientRectangle.Height))
    
            TrackBar1.Orientation = Orientation.Vertical
            TrackBar1.TickStyle = TickStyle.Both
            TrackBar1.Minimum = 0
            TrackBar1.SmallChange = 1
            TrackBar1.LargeChange = 1
            TrackBar1.Maximum = DataGridView1.Rows.Count - 3
            TrackBar1.Value = DataGridView1.Rows.Count - 3
    
        End Sub
    
        Dim OldVal As Integer = 0
        Dim FirstRun As Boolean = True
    
        Private Sub DoDGV(ByRef CurVal As Integer)
            If FirstRun = True Then
                FirstRun = False
            Else
                If CurVal > OldVal Then
                    DataGridView1.ClearSelection()
                    DataGridView1.Rows(DataGridView1.Rows.Count - 2).Selected = True
                    MVASS.CurrencyManager.Position = DataGridView1.Rows.Count - 2
                    If DataGridView1.Rows(0).Visible = True Then DataGridView1.Rows(0).Visible = False
                    For i = OldVal To CurVal
                        DataGridView1.Rows(i).Visible = False
                    Next
                ElseIf CurVal < OldVal Then
                    DataGridView1.ClearSelection()
                    DataGridView1.Rows(DataGridView1.Rows.Count - 2).Selected = True
                    MVASS.CurrencyManager.Position = DataGridView1.Rows.Count - 2
                    For i = OldVal To CurVal Step -1
                        DataGridView1.Rows(i).Visible = True
                    Next
                End If
            End If
            DataGridView1.Refresh()
            OldVal = CurVal
        End Sub
    
    
        Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
            DoDGV(Math.Abs(TrackBar1.Maximum - TrackBar1.Value))
        End Sub
    
    End Class


    La vida loca

    Saturday, May 07, 2016 12:11 AM

All replies

  • Hello,

    If you mean that the DataGridView has a set height and that the rows shown do not go to the bottom of the DataGridView there are two choices, first, is to set the background color of the DataGridView to the same color as the background color of the cells while the second is to calculate row height for total rows and row height to the canvas height of the DataGridView and adjust the height through the RowTemplate for the DataGridView which means in general rows will be taller and font size increase to look decent if possible or to shrink the height via calculations.

    To have the last row at the top, not knowing more than that you might look at sorting the data or change the method of adding data to the DataGridView. There are many variables to consider with limited information to provide an exact response to this task.


    Please remember to mark the replies as answers if they help and unmark them if they provide no help, this will help others who are looking for solutions to the same or similar problem. Contact via my Twitter (Karen Payne) or Facebook (Karen Payne) via my MSDN profile but will not answer coding question on either.
    VB Forums - moderator
    profile for Karen Payne on Stack Exchange, a network of free, community-driven Q&A sites

    Friday, May 06, 2016 12:53 PM
    Moderator
  • I want scroll last row to top of datagridview

    I can do that with panel by AutoScrollMargin
    but with datagridview I can't .

    Friday, May 06, 2016 6:09 PM
  • I want scroll last row to top of datagridview

    I can do that with panel by AutoScrollMargin
    but with datagridview I can't .

    The DataGridView has a specific clientsize for displaying the DataGridView rows and columns which works in conjunction with the DataGridView displaying scrollbars. The DataGridView appears to only be designed for using scrollbars when the clientsize is too small to for the entired display requirement for the DataGridView.

    Plus the DataGridView scrolling always displays the Columns regardless of the Rows.

    So I placed a DataGridView on a Form and set the ClientSize much larger than what the control actuall displays. This stops the Vertical ScrollBar from displaying though.

    I did not use a VScrollBar with the app. The VScrollBar never reaches its max value because the slider is not taken into account due to the sliders height for whatever reason. You could write code that correctly sets a max value for a VScrollBar such that the max value adds how much is required to get the desired max value in the VScrollBar that you want it to be able to scroll to but I didn't do that here.

    Also if you update the DGV so it has new rows added to it or a new table is bound to it or something that causes its ClientSize to need to be altered to accomodate that then you will need to use appropriate events and appropriate code from the below code to update necessary values.

    I used a TrackBar set to Vertical. The TrackBar thumb normally sits at the bottom of the TrackBar at value 0 when the TrackBar is set to vertical. You will note that I set the TrackBar to its max value in Form Load so that the slider button is at the top of the TrackBar.

    Also the retrieved TrackBar value is subtracted from the TrackBars max value so a 0 is provided when the TrackBar is at its max value and negative numbers are retrieved as the TrackBar moves down to 0. Math.Abs returns the absolute value of those equations which is a positive number.

    The DataGridView's Rows have their visibility set to False or True depending on the movement of the TrackBar. So the DataGridView isn't really scrolling but having rows hidden so other rows look like they are moving up and down.

    There is an issue with trying to set a rows visibility to False while the DataTables Currency Manager is in a DataGridView row if you are using a DataTable or possibly DataSet or something like that. Therefore the currency manager has to be moved somewhere so I just move it to the last row that contains data in the DataGridView.

    I also deselect everything which may not be necessary. I don't know if a selected row can have its visibility set to false and still be a selected item in DataGridViews Selected Rows or whatever.

    The DataGridView itself may function in this fashion for all I know in that as it's vertical scrollbar is used it hide/show rows. I have no idea. If that's true though then there may be all kinds of logic used by the DataGridView so it knows what rows, now not visible, are selected (if a non-visible row can not remain selected), etc. Although DataGridView probably just paints whatever it wants to display when the scrollbars are moved.

    If you anchor a DataGridView then you will need to use approriate events to reset values in necessary code to whatever the new values should be if the DataGridView resizes when the Form resizes if the anchors for the DGV resize it when that happens. Also if rows are added or deleted.

    In the test DGV the user was set to be allowed to add rows as the default which is why - 2 is used since the last row with data in it needs to be displayed. You could use an If or Select Case statement to determine if that value is true or false and set the other values appropriate.

    Option Strict On
    
    Public Class Form1
    
        WithEvents MultiVarAnalysis As New DataTable("SixSigma") ' Create DataTable with events.
        WithEvents MVASS As New BindingSource ' Create BindingSource with events.
    
        Private Sub Form1_Load(sender As Object, e As EventArgs) Handles MyBase.Load
            Me.Location = New Point(CInt((Screen.PrimaryScreen.WorkingArea.Width / 2) - (Me.Width / 2)), CInt((Screen.PrimaryScreen.WorkingArea.Height / 2) - (Me.Height / 2)))
    
            DataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect
            DataGridView1.Anchor = CType(AnchorStyles.Bottom + AnchorStyles.Left + AnchorStyles.Right + AnchorStyles.Top, AnchorStyles)
            DataGridView1.MultiSelect = False
            DataGridView1.AllowDrop = True
            DataGridView1.AutoSize = True
            DataGridView1.AutoSizeColumnsMode = DataGridViewAutoSizeColumnsMode.Fill
    
            MultiVarAnalysis.Columns.Add("Shift", GetType(String)) ' Represents FA
            MultiVarAnalysis.Columns("Shift").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Hello this is a long column", GetType(String)) ' Represents FB
            MultiVarAnalysis.Columns("Hello this is a long column").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Hour", GetType(String)) ' Represents FC
            MultiVarAnalysis.Columns("Hour").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Unit", GetType(String)) ' Represents FD
            MultiVarAnalysis.Columns("Unit").AllowDBNull = False
            MultiVarAnalysis.Columns.Add("Output", GetType(Double)) ' Represents Y
            MultiVarAnalysis.Columns("Output").AllowDBNull = False
    
    
            ' Add rows to DataTable
    
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U1", 0.947)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U2", 5.427)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U3", 8.334)
            MultiVarAnalysis.Rows.Add("A", "T1", "1st", "U4", 4.637)
    
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U1", 4.766)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U2", 4.461)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U3", 5.791)
            MultiVarAnalysis.Rows.Add("A", "T1", "2nd", "U4", 2.313)
    
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U1", 4.804)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U2", 5.238)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U3", 5.767)
            MultiVarAnalysis.Rows.Add("A", "T2", "1st", "U4", 5.108)
    
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U1", 3.829)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U2", 5.539)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U3", 8.18)
            MultiVarAnalysis.Rows.Add("A", "T2", "2nd", "U4", 4.86)
    
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U1", 3.339)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U2", 8.978)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U3", 9.681)
            MultiVarAnalysis.Rows.Add("B", "T1", "1st", "U4", 3.86)
    
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U1", 2.816)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U2", 5.519)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U3", 7.321)
            MultiVarAnalysis.Rows.Add("B", "T1", "2nd", "U4", 4.321)
    
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U1", 2.772)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U2", 7.431)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U3", 5.388)
            MultiVarAnalysis.Rows.Add("B", "T2", "1st", "U4", 6.911)
    
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U1", 3.5886)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U2", 8.043)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U3", 3.641)
            MultiVarAnalysis.Rows.Add("B", "T2", "2nd", "U4", 5.306)
    
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U1", 3.929)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U2", 4.164)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U3", 8.427)
            MultiVarAnalysis.Rows.Add("C", "T1", "1st", "U4", 3.835)
    
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U1", 4.936)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U2", 8.874)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U3", 8.38)
            MultiVarAnalysis.Rows.Add("C", "T1", "2nd", "U4", 5.214)
    
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U1", 4.059)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U2", 6.018)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U3", 4.035)
            MultiVarAnalysis.Rows.Add("C", "T2", "1st", "U4", 6.031)
    
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U1", 4.911)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U2", 8.189)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U3", 6.118)
            MultiVarAnalysis.Rows.Add("C", "T2", "2nd", "U4", 6.3)
    
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U1", 2.834)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U2", 4.142)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U3", 12.935)
            MultiVarAnalysis.Rows.Add("D", "T1", "1st", "U4", 12.834)
    
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U1", 4.487)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U2", 9.328)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U3", 10.0245)
            MultiVarAnalysis.Rows.Add("D", "T1", "2nd", "U4", 6.387)
    
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U1", 9.044)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U2", 6.322)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U3", 11.498)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U4", 7.943)
            MultiVarAnalysis.Rows.Add("D", "T2", "1st", "U5", 2.198)
    
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U1", 7.245)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U2", 13.918)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U3", 18.456)
            MultiVarAnalysis.Rows.Add("D", "T2", "2nd", "U4", 11.925)
    
            MultiVarAnalysis.AcceptChanges()
            MVASS.DataSource = MultiVarAnalysis
            DataGridView1.DataSource = MVASS
    
            For i = 0 To DataGridView1.ColumnCount - 1
                DataGridView1.Columns(i).SortMode = DataGridViewColumnSortMode.Automatic
            Next
    
            DataGridView1.ClientSize = New Size(DataGridView1.ClientRectangle.Width, CInt(DataGridView1.ColumnHeadersHeight + Math.Ceiling(DataGridView1.Rows.Count * DataGridView1.Rows(0).Height) + DataGridView1.ClientRectangle.Height))
    
            TrackBar1.Orientation = Orientation.Vertical
            TrackBar1.TickStyle = TickStyle.Both
            TrackBar1.Minimum = 0
            TrackBar1.SmallChange = 1
            TrackBar1.LargeChange = 1
            TrackBar1.Maximum = DataGridView1.Rows.Count - 3
            TrackBar1.Value = DataGridView1.Rows.Count - 3
    
        End Sub
    
        Dim OldVal As Integer = 0
        Dim FirstRun As Boolean = True
    
        Private Sub DoDGV(ByRef CurVal As Integer)
            If FirstRun = True Then
                FirstRun = False
            Else
                If CurVal > OldVal Then
                    DataGridView1.ClearSelection()
                    DataGridView1.Rows(DataGridView1.Rows.Count - 2).Selected = True
                    MVASS.CurrencyManager.Position = DataGridView1.Rows.Count - 2
                    If DataGridView1.Rows(0).Visible = True Then DataGridView1.Rows(0).Visible = False
                    For i = OldVal To CurVal
                        DataGridView1.Rows(i).Visible = False
                    Next
                ElseIf CurVal < OldVal Then
                    DataGridView1.ClearSelection()
                    DataGridView1.Rows(DataGridView1.Rows.Count - 2).Selected = True
                    MVASS.CurrencyManager.Position = DataGridView1.Rows.Count - 2
                    For i = OldVal To CurVal Step -1
                        DataGridView1.Rows(i).Visible = True
                    Next
                End If
            End If
            DataGridView1.Refresh()
            OldVal = CurVal
        End Sub
    
    
        Private Sub TrackBar1_Scroll(sender As Object, e As EventArgs) Handles TrackBar1.Scroll
            DoDGV(Math.Abs(TrackBar1.Maximum - TrackBar1.Value))
        End Sub
    
    End Class


    La vida loca

    Saturday, May 07, 2016 12:11 AM
  • Hi, If it is for web application,

    we could try with the css, refer the below.

    http://stackoverflow.com/questions/7206997/no-border-spacing-before-first-item-and-after-last-item

    https://css-tricks.com/filling-space-last-row-flexbox/

    Hope this helps.


    Saturday, May 07, 2016 12:55 AM