Results 1 to 4 of 4

Thread: How to make visible the scrollbar of a datagridview that starts without data?

  1. #1

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    8

    Question How to make visible the scrollbar of a datagridview that starts without data?

    Hello, I had programmed a button to call a database access as follows:

    Principal
    Code:
    Private Sub VerTablaToolStripMenuItem_Click(sender As Object, e As EventArgs) Handles VerTablaToolStripMenuItem.Click
    Code:
    Dim cnn As New OleDbConnection("Provider=Microsoft.ACE.OLEDB.12.0;Data Source= data\Frg.accdb;Persist Security Info=False")
            Dim da As New OleDbDataAdapter("SELECT * FROM Tabla1 ", cnn)
            Dim ds As New DataSet
            da.Fill(ds)
            DataGridView1.DataSource = ds.Tables(0)
            DataGridView1.ScrollBars = ScrollBars.Both ' example but not working
    Code:
    End Sub
    Now I understand that the code shows the database to datagridview1, but it turns out that in columns I have an approximate of 9 columns, now when I run the program it shows some horizontal data that are 5 that I can see on the screen and Worst of all is that I do not see the scrollbar or scrollbar,

    under the previous code I had placed this
    preview access
    Name:  access.jpg
Views: 3114
Size:  9.8 KB
    preview VB.NET
    Name:  vs.jpg
Views: 3208
Size:  19.9 KB

  2. #2
    eXtreme Programmer .paul.'s Avatar
    Join Date
    May 2007
    Location
    Chelmsford UK
    Posts
    26,413

    Re: How to make visible the scrollbar of a datagridview that starts without data?

    You can customize your DGV, but I don't think that's the problem in this case. Here's how...

    Code:
    Public Class CustomDgv
        Inherits DataGridView
    
        Private Const CAPTIONHEIGHT As Integer = 21
        Private Const BORDERWIDTH As Integer = 1
    
        Public Sub New()
            ' make scrollbars visible & add handler
            Try
                VerticalScrollBar.Visible = True
                HorizontalScrollBar.Visible = True
            Catch
    
            End Try
    
            AddHandler VerticalScrollBar.VisibleChanged, AddressOf ShowVScrollBar
            AddHandler HorizontalScrollBar.VisibleChanged, AddressOf ShowHScrollBar
        End Sub
    
        Private Sub ShowVScrollBar(ByVal sender As Object, ByVal e As EventArgs)
            Try
                If Not VerticalScrollBar.Visible Then
                    Dim width As Integer = VerticalScrollBar.Width
                    VerticalScrollBar.Location = New Point(ClientRectangle.Width - width - BORDERWIDTH, 1)
                    VerticalScrollBar.Size = New Size(width, ClientRectangle.Height - HorizontalScrollBar.Height - BORDERWIDTH - 1)
                    VerticalScrollBar.Show()
                End If
            Catch
    
            End Try
        End Sub
    
        Private Sub ShowHScrollBar(ByVal sender As Object, ByVal e As EventArgs)
            Try
                If Not HorizontalScrollBar.Visible Then
                    HorizontalScrollBar.Location = New Point(1, VerticalScrollBar.Bottom - BORDERWIDTH + 1)
                    HorizontalScrollBar.Size = New Size(ClientRectangle.Width - VerticalScrollBar.Width - 2, HorizontalScrollBar.Height)
                    HorizontalScrollBar.Show()
                End If
            Catch
    
            End Try
        End Sub
    
    End Class

  3. #3
    Super Moderator jmcilhinney's Avatar
    Join Date
    May 2005
    Location
    Sydney, Australia
    Posts
    111,221

    Re: How to make visible the scrollbar of a datagridview that starts without data?

    Your question doesn't make much sense. Are you saying that the scrollbars don't appear even when there's data that requires scrolling? If so, don't you think that showing a screenshot of that instead of those other two might have been useful? If that's not what you're saying, what are you saying?
    Why is my data not saved to my database? | MSDN Data Walkthroughs
    VBForums Database Development FAQ
    My CodeBank Submissions: VB | C#
    My Blog: Data Among Multiple Forms (3 parts)
    Beginner Tutorials: VB | C# | SQL

  4. #4

    Thread Starter
    New Member
    Join Date
    Dec 2017
    Posts
    8

    Re: How to make visible the scrollbar of a datagridview that starts without data?

    ok, tank you

Tags for this Thread

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width