Click here to Skip to main content
15,897,032 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
i am running a program in which the list of documents is visible in the listbox and the image is shown in the picture box. but when i run the code and when i select a document in the listbox ,i got its image in the picturebox but when i select another document i dint get its respective image in picturebox. the image remains static in the picturebox when i clicked the first document......
plz help me plzzz...........her's my code

-------------------------------code--------------------------------------------------

VB
Private Sub ListBox1_SelectedIndexChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles ListBox1.SelectedIndexChanged
     'tb_sno.Enabled = False

     tb_name.Enabled = False
     cb_school.Enabled = False
     'cb_doctype.Enabled = False
     Dim test As String = ListBox1.Text
     tb_sno.Text = ListBox1.Text.Remove(ListBox1.Text.IndexOf(" "))


     If con.State <> ConnectionState.Open Then
         con.Open()
     End If
     GroupBox3.Visible = True
     Dim dr As SqlDataReader
     Dim sid As String
     sid = ComboBox1.SelectedItem.ToString
     sid = sid.Substring(0, 9)
     ' school = ComboBox2.Text
     'dname = ListBox1.Items.Add(dr(0))
     Dim cmd As New SqlCommand("select * from studentmaster a, hbetscan b where a.studentid='" & sid & "' and a.studentid=b.studentid ", con)
     cmd.CommandTimeout = 0
     cmd.ExecuteNonQuery()
     dr = cmd.ExecuteReader
     If dr.Read Then
         tb_sid.Text = dr("studentid")
         tb_name.Text = dr("studentname")
         cb_school.Text = dr("schoolname")
         cb_doctype.Text = dr("doctype")
         Dim imgdata() As Byte = dr("image")
         Dim img As Image
         Dim ms As MemoryStream = New MemoryStream(imgdata, 0, imgdata.Length)
         ms.Write(imgdata, 0, imgdata.Length)
         img = Image.FromStream(ms, True)
         PictureBox1.Image = img
         PictureBox1.Image.Save("c:\" & "img1.jpg", System.Drawing.Imaging.ImageFormat.Jpeg)
         dr.Close()
         con.Close()
         ms.Close()
         'ms.Dispose()


     End If
 End Sub
Posted

1 solution

As seen from the following code given in the question, the sid is set from ComboBox1
VB
sid = ComboBox1.SelectedItem.ToString
sid = sid.Substring(0, 9)

which is used later in the sqlcommand to retrieve data from the database.
Whereas the ListBox1_SelectedIndexChanged event is used to change the image in the PictureBox.
This may be the reason as the selection change in ListBox1 will not be reflected in ComboBox1. Please check.
 
Share this answer
 
Comments
ashwani.pandita 17-Apr-12 2:53am    
sir in combobox1 i select the student name and in listbox i got its various documents like progress report,address proof,medical report etc, and what you suggested din't works , plz help me with some other solutions.......
VJ Reddy 17-Apr-12 3:30am    
As seen from the sqlcommand text given in the question sid is the only variable, which is being set from ComboBox1. Now, when the selection index of ListBox1 is changed, which variable is being used in the command to retrieve the corresponding data for displaying in the picture box.
ashwani.pandita 17-Apr-12 3:48am    
sir i am new in this field and trying a lot to grab as soon as possible. thanx a lot for your help but sir i still dint get you .plz assist me in detail if you dont mind,plzzzzzzzzzzzz

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