Solved

Trackbar To Flip Through Photos

Posted on 2008-06-20
14
229 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
  • 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
 
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
Maximize Your Threat Intelligence Reporting

Reporting is one of the most important and least talked about aspects of a world-class threat intelligence program. Here’s how to do it right.

 
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 500 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

How your wiki can always stay up-to-date

Quip doubles as a “living” wiki and a project management tool that evolves with your organization. As you finish projects in Quip, the work remains, easily accessible to all team members, new and old.
- Increase transparency
- Onboard new hires faster
- Access from mobile/offline

Join & Write a Comment

If you're writing a .NET application to connect to an Access .mdb database and use pre-existing queries that require parameters, you've come to the right place! Let's say the pre-existing query(qryCust) in Access takes a Date as a parameter and l…
A while ago, I was working on a Windows Forms application and I needed a special label control with reflection (glass) effect to show some titles in a stylish way. I've always enjoyed working with graphics, but it's never too clever to re-invent …
Excel styles will make formatting consistent and let you apply and change formatting faster. In this tutorial, you'll learn how to use Excel's built-in styles, how to modify styles, and how to create your own. You'll also learn how to use your custo…
You have products, that come in variants and want to set different prices for them? Watch this micro tutorial that describes how to configure prices for Magento super attributes. Assigning simple products to configurable: We assigned simple products…

757 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

Need Help in Real-Time?

Connect with top rated Experts

19 Experts available now in Live!

Get 1:1 Help Now