?
Solved

Trackbar To Flip Through Photos

Posted on 2008-06-20
14
Medium Priority
?
251 Views
Last Modified: 2010-04-23
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
Comment
Question by:H-SC
[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
  • 8
  • 6
14 Comments
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21832761
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
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21832915
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
 
LVL 1

Author Comment

by:H-SC
ID: 21833351
Steve,

Many thanks for this.  How can I use this with the current datasets/adapters that I have in place?
0
Technology Partners: 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!

 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21833370
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
 
LVL 1

Author Comment

by:H-SC
ID: 21833666
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
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21833710
Sounds like the dt.Rows.Count is returning 0

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

0
 
LVL 1

Author Comment

by:H-SC
ID: 21833888
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
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21833942
You need to remove "New" from Dim dt As New ds.YourDataTable()

Regards
Steve
0
 
LVL 1

Author Comment

by:H-SC
ID: 21834177
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
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21834254
It would be best if you posted some code

In particular your db code

Regards
Steve
0
 
LVL 1

Author Comment

by:H-SC
ID: 21834360
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
 
LVL 19

Expert Comment

by:Stephen Manderson
ID: 21839075
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
 
LVL 19

Accepted Solution

by:
Stephen Manderson earned 2000 total points
ID: 21839084
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
 
LVL 1

Author Comment

by:H-SC
ID: 21899167
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

Featured Post

Free Tool: IP Lookup

Get more info about an IP address or domain name, such as organization, abuse contacts and geolocation.

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.

Question has a verified solution.

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

Creating an analog clock UserControl seems fairly straight forward.  It is, after all, essentially just a circle with several lines in it!  Two common approaches for rendering an analog clock typically involve either manually calculating points with…
If you need to start windows update installation remotely or as a scheduled task you will find this very helpful.
NetCrunch network monitor is a highly extensive platform for network monitoring and alert generation. In this video you'll see a live demo of NetCrunch with most notable features explained in a walk-through manner. You'll also get to know the philos…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Suggested Courses
Course of the Month9 days, 7 hours left to enroll

762 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