Click here to Skip to main content
15,897,371 members
Please Sign up or sign in to vote.
3.00/5 (2 votes)
See more:
i have 4 picture box's on a form and i want to retrieve images from database and provide navigations, on a combo box selection ... i have tried a lot but all my picture box's are retrieving some random images and only first picturebox is following the navigations and that too not properlyy... please help.. stucked up badlyy.... thnxx in advance..!!!


VB
Dim con As New SqlConnection("Data Source=hp-pc;Initial Catalog=DB_RoyalProject;Integrated Security=True")
    Dim da As New SqlDataAdapter("Select * from TB_Tile_Layout_Patterns where Tile_Patterns_ID=1", con)
    Dim ds As New DataSet
    Dim dv As New DataView
    Dim c As CurrencyManager
 
    Public Sub fill()
 
        da.Fill(ds, "TB_Tile_Layout_Patterns")
        dv = New DataView(ds.Tables("TB_Tile_Layout_Patterns"))
 
        c = CType(Me.BindingContext(dv), CurrencyManager)
 
end sub



Public Sub bind()
        lbl_ptrn1.DataBindings.Clear()
        lbl_ptrn2.DataBindings.Clear()
        lbl_ptrn3.DataBindings.Clear()
        lbl_ptrn4.DataBindings.Clear()
        lbl_dmnsn1.DataBindings.Clear()
        lbl_dmnsn2.DataBindings.Clear()
        lbl_dmnsn3.DataBindings.Clear()
        lbl_dmnsn4.DataBindings.Clear()
        PictureBox1.DataBindings.Clear()
        PictureBox2.DataBindings.Clear()
        PictureBox3.DataBindings.Clear()
        PictureBox4.DataBindings.Clear()
 
        lbl_ptrn1.DataBindings.Add("text", dv, "Tile_Layout_Patterns")
        lbl_ptrn2.DataBindings.Add("text", dv, "Tile_Layout_Patterns")
        lbl_ptrn3.DataBindings.Add("text", dv, "Tile_Layout_Patterns")
        lbl_ptrn4.DataBindings.Add("text", dv, "Tile_Layout_Patterns")
        lbl_dmnsn1.DataBindings.Add("text", dv, "Dimension_Of_Tile1")
        lbl_dmnsn2.DataBindings.Add("text", dv, "Dimension_Of_Tile1")
        lbl_dmnsn3.DataBindings.Add("text", dv, "Dimension_Of_Tile1")
        lbl_dmnsn4.DataBindings.Add("text", dv, "Dimension_Of_Tile1")
        PictureBox1.DataBindings.Add("imagelocation", dv, "Tile_Layout_Patterns_Image")
        PictureBox2.DataBindings.Add("imagelocation", dv, "Tile_Layout_Patterns_Image")
        PictureBox3.DataBindings.Add("imagelocation", dv, "Tile_Layout_Patterns_Image")
        PictureBox4.DataBindings.Add("imagelocation", dv, "Tile_Layout_Patterns_Image")


    Private Sub ComboBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ComboBox1.SelectedIndexChanged
 If ComboBox1.SelectedItem = "One Tile Patterns" Then
            Label4.Text = "One Tile Patterns"

            lbl_dsgn1.Visible = False
            lbl_dsgn2.Visible = False
            lbl_dsgn3.Visible = False
            lbl_dsgn4.Visible = False

            lbl_ptrn1.Visible = True
            lbl_ptrn2.Visible = True
            lbl_ptrn3.Visible = True
            lbl_ptrn4.Visible = True
            lbl_dmnsn1.Visible = True
            lbl_dmnsn2.Visible = True
            lbl_dmnsn3.Visible = True
            lbl_dmnsn4.Visible = True


            con.Open()
            Dim cmd As New SqlCommand("Select * from TB_Tile_Layout_Patterns where Tile_Patterns_ID=1", con)
            Dim dr As SqlDataReader
            dr = cmd.ExecuteReader


            While (dr.Read)
                lbl1.Text = dr(2)
                lbl2.Text = dr(5)
                pb1.ImageLocation = dr(3)
                Exit While
            End While


            While (dr.Read)
                lbl_ptrn1.Text = dr(2)
                lbl_dmnsn1.Text = dr(5)
                PictureBox1.ImageLocation = dr(3)
                Exit While
            End While

            While (dr.Read)
                lbl_ptrn2.Text = dr(2)
                lbl_dmnsn2.Text = dr(5)
                PictureBox2.ImageLocation = dr(3)
                Exit While
            End While

            While (dr.Read)
                lbl_ptrn3.Text = dr(2)
                lbl_dmnsn3.Text = dr(5)
                PictureBox3.ImageLocation = dr(3)
                Exit While
            End While

            While (dr.Read)
                lbl_ptrn4.Text = dr(2)
                lbl_dmnsn4.Text = dr(5)
                PictureBox4.ImageLocation = dr(3)
                Exit While
            End While
            con.Close()
        End If
    End Sub


'navigations..

    Private Sub LinkLabel3_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelgn.LinkClicked
        c.Position = c.Position + 1

    End Sub

    Private Sub LinkLabel1_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelgf.LinkClicked
      
        While (c.Position = 0)

        End While
        If (c.Position = 0) Then
            MsgBox("First Record")
        Else
            c.Position = c.Position - 1
        End If
    End Sub

    Private Sub LinkLabel4_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelgp.LinkClicked
        If (c.Position = c.Count - 1) Then
            MsgBox("This is the last record")
        Else
            c.Position = c.Position + 1
        End If
        bind()
    End Sub

    Private Sub LinkLabel2_LinkClicked(ByVal sender As System.Object, ByVal e As System.Windows.Forms.LinkLabelLinkClickedEventArgs) Handles LinkLabelgl.LinkClicked
        c.Position = c.Count - 1
        bind()
    End Sub
End Class
Posted
Updated 11-Nov-12 19:53pm
v2
Comments
Nelek 11-Nov-12 16:00pm    
please read: what have you tried?[^]
You are telling you tried a lot and it is not working, but you are not giving any usefull information to us, so it is quite difficult to help you. We can not read minds or do astral projections to see your computer to know where the error is.
Please use the "improve question" widget and add some pieces of the code that is giving you problems.
Sergey Alexandrovich Kryukov 11-Nov-12 23:28pm    
Sorry, I removed your code you posted as "Solution". This is not solution, and the post should be removed. Please add the code to the body of the question using "Improve question" above.
--SA
Mustafa_9664 12-Nov-12 15:21pm    
Someone please help as i desperately need it..!!!!
ZurdoDev 12-Nov-12 16:36pm    
Nothing is random in computers so have you stepped through the code? That's the only way you'll find why it's loading a "random" image.
Kschuler 13-Nov-12 10:55am    
Can you be more specific about how it is not working? What is currently happening, and what do you WANT to happen? I noticed that you didn't use any ORDER BY clauses in your SQL. If you are expecting the pictures to appear in a certain order, perhaps you should look into that.

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900