TECHNOLOGIES
FORUMS
JOBS
BOOKS
EVENTS
INTERVIEWS
Live
MORE
LEARN
Training
CAREER
MEMBERS
VIDEOS
NEWS
BLOGS
Sign Up
Login
No unread comment.
View All Comments
No unread message.
View All Messages
No unread notification.
View All Notifications
Answers
Post
An Article
A Blog
A News
A Video
An EBook
An Interview Question
Ask Question
Forums
Monthly Leaders
Forum guidelines
keyvan
NA
34
0
add picturebox to panel get data from db error
Sep 30 2013 11:33 AM
Hi
I have the following code which gets the pictures from the database and add a picturebox for each picture field to the panel1
but i have problems with displaying the right records since it should position the pictureboxes int the panel i got a code from google and used it in my code so that it positions the picturex correctly but i do not get the right records since i use both while wend and for i loop
please correct it
Private Sub Auto_AutosBindingSource_PositionChanged(sender As Object, e As System.EventArgs) Handles Auto_AutosBindingSource.PositionChanged
If Me.Auto_AutosBindingSource.Position > -1 Then
Dim rowID As AutosDataSet.auto_AutosRow
rowID = CType(CType(Me.Auto_AutosBindingSource.Current, DataRowView).Row, AutosDataSet.auto_AutosRow)
Panel1.Controls.Clear()
Dim dr As SqlDataReader
Dim conn As New SqlConnection(My.Settings.conn)
Dim cmd As New SqlCommand("select * from auto_Photos where ListingID=" & rowID.ID.ToString, conn)
conn.Open()
dr = cmd.ExecuteReader()
If dr.HasRows Then
Dim bottomlist As New List(Of Integer)()
While dr.Read()
For i As Integer = 0 To dr.Read()
Dim pb As New PictureBox()
If i = 0 Then
bottomlist.Add(pb.Bottom + 8)
Else
bottomlist.Add(pb.Bottom + bottomlist(i - 1) + 8)
End If
If i = 0 Then
pb.Top = 8
Else
pb.Top = bottomlist(i - 1) + 8
End If
pb.Left = (Panel1.ClientSize.Width - pb.Width) / 2
pb.Size = New Size(480, 360)
pb.ImageLocation = My.Settings.ApplicationURL & "/pictures/autoImages/" & dr("Folder").ToString & "/" & common.getPicThumb(dr("Photo").ToString)
pb.Width = "100"
pb.Height = "100"
Panel1.Controls.Add(pb)
Next
End While
End If
dr.Close()
conn.Close()
End If
Reply
Answers (
0
)
Deploy Windows Forms app with Database
Upload file on database using C#