?
Solved

Scrollbar ???

Posted on 2005-03-21
4
Medium Priority
?
380 Views
Last Modified: 2010-04-23
I have a form with different fields from my access table and I want to use a scrollbar to navigate the table.
How do I bind the dataset to the scrollbar?
Also, what are the events when clicking the scrollbar?

Thanks in advance,
0
Comment
Question by:Mylor
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
4 Comments
 
LVL 1

Expert Comment

by:gregspence
ID: 13596802
There are no data binding events for a scrollbar.

Your best bet is to load the data into a Dataset first so you can access it dynamically and move both forward and backward.  A datareader wont help you in this situation.

Once you have the dataset, you can setup the properties for your scrollbar.  Set your minimum value to zero which will correspond to record zero.  Set the max value to Dataset.Tables(0).Rows.Count - 1.  This will insure that a user can't scroll past the maximum number of records in the dataset.

Respond to the following event and access your dataset.  The NewValue parameter will correspond with the row index that you want to access.

    Private Sub VScrollBar1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles VScrollBar1.Scroll
        Dim Row as Datarow
        Row = MyDataset.Tables(0).Rows(e.NewValue)
        'Set your control values here
        Textbox1.Text = Row.Item("FirstName")
    End Sub

You could take some much more complex approaches if you truly wanted to create a DataBinder for a scrollbar, but I'm not sure if you really want to go through that trouble.
0
 

Author Comment

by:Mylor
ID: 13597222
What do you mean where you wrote?:

   'Set your control values here
0
 
LVL 14

Accepted Solution

by:
amyhxu earned 1500 total points
ID: 13597708
I don't think using scroll bar is a good approach in this case. You may use the database navigation technique as shown in the following links:
http://www.homeandlearn.co.uk/NET/nets12p7.html
http://www.vb-helper.com/howto_net_navigate_database.html


0
 
LVL 1

Expert Comment

by:gregspence
ID: 13602024
Ok, this should help.  This simple form binds 2 controls to a dataset that was generated with code.  The scrollbar navigates the records.

Public Class Form1
    Inherits System.Windows.Forms.Form

#Region " Windows Form Designer generated code "

    Public Sub New()
        MyBase.New()

        'This call is required by the Windows Form Designer.
        InitializeComponent()

        'Add any initialization after the InitializeComponent() call

    End Sub

    'Form overrides dispose to clean up the component list.
    Protected Overloads Overrides Sub Dispose(ByVal disposing As Boolean)
        If disposing Then
            If Not (components Is Nothing) Then
                components.Dispose()
            End If
        End If
        MyBase.Dispose(disposing)
    End Sub

    'Required by the Windows Form Designer
    Private components As System.ComponentModel.IContainer

    'NOTE: The following procedure is required by the Windows Form Designer
    'It can be modified using the Windows Form Designer.  
    'Do not modify it using the code editor.
    Friend WithEvents txtName As System.Windows.Forms.TextBox
    Friend WithEvents Label1 As System.Windows.Forms.Label
    Friend WithEvents Label2 As System.Windows.Forms.Label
    Friend WithEvents txtAddress As System.Windows.Forms.TextBox
    Friend WithEvents Scroll1 As System.Windows.Forms.HScrollBar
    <System.Diagnostics.DebuggerStepThrough()> Private Sub InitializeComponent()
        Me.txtName = New System.Windows.Forms.TextBox
        Me.Label1 = New System.Windows.Forms.Label
        Me.Label2 = New System.Windows.Forms.Label
        Me.txtAddress = New System.Windows.Forms.TextBox
        Me.Scroll1 = New System.Windows.Forms.HScrollBar
        Me.SuspendLayout()
        '
        'txtName
        '
        Me.txtName.Location = New System.Drawing.Point(128, 16)
        Me.txtName.Name = "txtName"
        Me.txtName.TabIndex = 0
        Me.txtName.Text = ""
        '
        'Label1
        '
        Me.Label1.Location = New System.Drawing.Point(16, 16)
        Me.Label1.Name = "Label1"
        Me.Label1.TabIndex = 1
        Me.Label1.Text = "Name"
        '
        'Label2
        '
        Me.Label2.Location = New System.Drawing.Point(16, 48)
        Me.Label2.Name = "Label2"
        Me.Label2.TabIndex = 3
        Me.Label2.Text = "Address"
        '
        'txtAddress
        '
        Me.txtAddress.Location = New System.Drawing.Point(128, 48)
        Me.txtAddress.Name = "txtAddress"
        Me.txtAddress.TabIndex = 2
        Me.txtAddress.Text = ""
        '
        'Scroll1
        '
        Me.Scroll1.Dock = System.Windows.Forms.DockStyle.Bottom
        Me.Scroll1.Location = New System.Drawing.Point(0, 93)
        Me.Scroll1.Name = "Scroll1"
        Me.Scroll1.Size = New System.Drawing.Size(352, 17)
        Me.Scroll1.TabIndex = 4
        '
        'Form1
        '
        Me.AutoScaleBaseSize = New System.Drawing.Size(5, 13)
        Me.ClientSize = New System.Drawing.Size(352, 110)
        Me.Controls.Add(Me.Scroll1)
        Me.Controls.Add(Me.Label2)
        Me.Controls.Add(Me.txtAddress)
        Me.Controls.Add(Me.Label1)
        Me.Controls.Add(Me.txtName)
        Me.Name = "Form1"
        Me.Text = "Form1"
        Me.ResumeLayout(False)

    End Sub

#End Region

    Private MyDataset As DataSet

    Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load

        GenerateDataset()

        'Setup Scrollbar
        Scroll1.Minimum = 0
        Scroll1.Maximum = MyDataset.Tables(0).Rows.Count

        'Bind Controls to Dataset
        txtName.DataBindings.Add("Text", MyDataset, "MyTable.Name")
        txtAddress.DataBindings.Add("Text", MyDataset, "MyTable.Address")

    End Sub

    Private Sub GenerateDataset()

        MyDataset = New DataSet
        MyDataset.Tables.Add(New DataTable("MyTable"))
        MyDataset.Tables(0).Columns.Add(New DataColumn("Name"))
        MyDataset.Tables(0).Columns.Add(New DataColumn("Address"))

        Dim row As DataRow
        For i As Integer = 1 To 50
            row = MyDataset.Tables(0).NewRow()
            row.Item("Name") = "Name " & i
            row.Item("Address") = "Address " & i
            MyDataset.Tables(0).Rows.Add(row)
        Next

    End Sub

    Private Sub Scroll1_Scroll(ByVal sender As System.Object, ByVal e As System.Windows.Forms.ScrollEventArgs) Handles Scroll1.Scroll
        Me.BindingContext(MyDataset, "MyTable").Position = e.NewValue
    End Sub

End Class
0

Featured Post

Independent Software Vendors: We Want Your Opinion

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Since .Net 2.0, Visual Basic has made it easy to create a splash screen and set it via the "Splash Screen" drop down in the Project Properties.  A splash screen set in this manner is automatically created, displayed and closed by the framework itsel…
Parsing a CSV file is a task that we are confronted with regularly, and although there are a vast number of means to do this, as a newbie, the field can be confusing and the tools can seem complex. A simple solution to parsing a customized CSV fi…
In this video, Percona Director of Solution Engineering Jon Tobin discusses the function and features of Percona Server for MongoDB. How Percona can help Percona can help you determine if Percona Server for MongoDB is the right solution for …
In this video, Percona Solution Engineer Rick Golba discuss how (and why) you implement high availability in a database environment. To discuss how Percona Consulting can help with your design and architecture needs for your database and infrastr…
Suggested Courses
Course of the Month11 days, 14 hours left to enroll

752 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question