picturebox binding
-
Hello, I want to keep the personal details including a picture of a user and store this information in a database and display later. I binded the textboxes to a datatable but could not bind the picturebox and the image. I tried the code below.. How can I handle that?? string selectStudent = "SELECT * FROM Students "; daStudent = new SqlDataAdapter(selectStudent, conn); dsStudent = new DataSet(); cbStudent = new SqlCommandBuilder(daStudent); daStudent.Fill(dsStudent, "Students"); pictureBox.DataBindings.Add("Byte[]", dsStudent, "Students.Photo");
-
Hello, I want to keep the personal details including a picture of a user and store this information in a database and display later. I binded the textboxes to a datatable but could not bind the picturebox and the image. I tried the code below.. How can I handle that?? string selectStudent = "SELECT * FROM Students "; daStudent = new SqlDataAdapter(selectStudent, conn); dsStudent = new DataSet(); cbStudent = new SqlCommandBuilder(daStudent); daStudent.Fill(dsStudent, "Students"); pictureBox.DataBindings.Add("Byte[]", dsStudent, "Students.Photo");
You can bind picturebox using Format event
... // your code goes here ... Binding binding = new Binding("Image", dsStudent, "Students.Photo"); binding.Format+=new ConvertEventHandler(binding_Format); pictureBox.DataBindings.Add(binding);
And in Format event you must convert byte [] array to Imageprivate void binding_Format(object sender, ConvertEventArgs e) { using(MemoryStream stream = new MemoryStream((byte [])e.Value)) { e.Value = Image.FromStream(stream); } }
DevIntelligence.com - My blog for .Net Developers