Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Trackbar To Flip Through Photos

Posted on 2008-06-20
14
Medium Priority
?
262 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
What does it mean to be "Always On"?

Is your cloud always on? With an Always On cloud you won't have to worry about downtime for maintenance or software application code updates, ensuring that your bottom line isn't affected.

 
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

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

It’s quite interesting for me as I worked with Excel using vb.net for some time. Here are some topics which I know want to share with others whom this might help. First of all if you are working with Excel then you need to Download the Following …
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
Visualize your data even better in Access queries. Given a date and a value, this lesson shows how to compare that value with the previous value, calculate the difference, and display a circle if the value is the same, an up triangle if it increased…
This lesson discusses how to use a Mainform + Subforms in Microsoft Access to find and enter data for payments on orders. The sample data comes from a custom shop that builds and sells movable storage structures that are delivered to your property. …
Suggested Courses

604 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