Improve company productivity with a Business Account.Sign Up

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 270
  • Last Modified:

Trackbar To Flip Through Photos

I have a dataset for a table that has paths to various photos stored in it.  I would like to use a trackbar to flip through the photos displaying them using picturebox1 on my form.  I am thinking that the event would be similar to a next function using the trackbar1.scroll routine, but not sure.  How can this be done?
0
H-SC
Asked:
H-SC
  • 8
  • 6
1 Solution
 
Stephen MandersonSoftware EngineerCommented:
You could use the scroll event to get the TrackBar1.Value (Integer) and of course set the picturebox to an image from file from the path in the dataset, where the dataset index is equal to the trackbar1.value

Regards
Steve
0
 
Stephen MandersonSoftware EngineerCommented:
This should get you started. you will need to add some error handling if there is no paths etc..

Regards
Steve
Dim pathList As New List(Of String)
......
 
 
Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load
        Dim dt As New ds.YourDataTable() 'change to suit
        Dim row As ds.TableFileRow 'change to suit
 
        TrackBar1.Maximum = dt.Rows.Count
 
        For Each row In dt.Rows
            pathList.Add(row.Item("path"))
        Next
    End Sub
 
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        PictureBox1.Image = Image.FromFile(pathList.Item(TrackBar1.Value))
    End Sub

Open in new window

0
 
H-SCAuthor Commented:
Steve,

Many thanks for this.  How can I use this with the current datasets/adapters that I have in place?
0
Free Tool: Site Down Detector

Helpful to verify reports of your own downtime, or to double check a downed website you are trying to access.

One of a set of tools we are providing to everyone as a way of saying thank you for being a part of the community.

 
Stephen MandersonSoftware EngineerCommented:
you just need to change the 2 lines I commented on to match your own ds.Tableadapter and you should be able to slide through the images.

Regards
Steve
0
 
H-SCAuthor Commented:
Steve,

I  set the dt and ds items and builds with no errors, but the trackbar does not move.  It almost seems that it is not enabled.
0
 
Stephen MandersonSoftware EngineerCommented:
Sounds like the dt.Rows.Count is returning 0

do msgbox(dt.Rows.Count.tostring) to confirm

0
 
H-SCAuthor Commented:
it looks as though the count is indeed 0, but when I go into the xsd and preview I get 15 rows from the datatable.  I am not sure what I may be doing wrong..
0
 
Stephen MandersonSoftware EngineerCommented:
You need to remove "New" from Dim dt As New ds.YourDataTable()

Regards
Steve
0
 
H-SCAuthor Commented:
Steve,

When I did that I get an error of variable 'dt' is used before it has been assigned a value.  for line:
 TrackBar1.Maximum = dt.Rows.Count
0
 
Stephen MandersonSoftware EngineerCommented:
It would be best if you posted some code

In particular your db code

Regards
Steve
0
 
H-SCAuthor Commented:
Steve,

Thanks for your efforts on this.  Here is what I have so far...

Me.Active_postersTableAdapter1.Fill(Me.Activemedia.posters123)
        Dim dt As activemedia.posters123DataTable
        Dim row As activemedia.posters123Row
        TrackBar1.Maximum = dt.Rows.Count
        For Each row In dt.Rows
            pathList.Add(row.Item("display_poster"))
        Next
        MsgBox(dt.Rows.Count.ToString)
0
 
Stephen MandersonSoftware EngineerCommented:
Hi there,

If you only want the datatable declared as a local then you will require "New" sorry I assumed you already had your table declared.

So you need to put this back in. You are not filling the new instance of the datatable created you need to fill "dt" after it has been declared ie..


        Dim dt As New activemedia.posters123DataTable
        Dim row As activemedia.posters123Row

        Me.Active_postersTableAdapter1.Fill(dt)

        TrackBar1.Maximum = dt.Rows.Count

        For Each row In dt.Rows
            pathList.Add(row.Item("display_poster"))
        Next

Regards
Steve
0
 
Stephen MandersonSoftware EngineerCommented:
Here is my full class I have tested this with.

Works perfectly fine.

Regards
Steve
Public Class Form1
 
    Dim pathList As New List(Of String)
 
    Private Sub Form1_Load(ByVal sender As Object, ByVal e As System.EventArgs) Handles Me.Load
 
        Dim dt As New ImagePathsDataSet.PathsDataTable 'change to suit
        Dim row As ImagePathsDataSet.PathsRow 'change to suit
 
        PathsTableAdapter1.Fill(dt)
 
        TrackBar1.Maximum = dt.Rows.Count - 1
 
        For Each row In dt.Rows
            pathList.Add(row.Item("paths"))
        Next
 
        PictureBox1.Image = Image.FromFile(pathList.Item(TrackBar1.Value).ToString)
 
    End Sub
 
    Private Sub TrackBar1_Scroll(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles TrackBar1.Scroll
        PictureBox1.Image = Image.FromFile(pathList.Item(TrackBar1.Value).ToString)
    End Sub
 
End Class

Open in new window

0
 
H-SCAuthor Commented:
Steve,

It works perfect!  I was leaving out the .... Me.Active_postersTableAdapter1.Fill(dt)


many thanks again for the much needed help on this
0
Question has a verified solution.

Are you are experiencing a similar issue? Get a personalized answer when you ask a related question.

Have a better answer? Share it in a comment.

Join & Write a Comment

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

  • 8
  • 6
Tackle projects and never again get stuck behind a technical roadblock.
Join Now