Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations Chriss Miller on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

PictureBox && Binding

Status
Not open for further replies.

Ginka

Programmer
Mar 18, 2005
54
MX
I don't know if I'm doing something wrong

I'm binding others controls and it is very easy, but the pictureBox doesn't work

I mean
Code:
textBoxAny.DataBindings.Add("Text",dataSet.Tables["MyTable"],"MyTextField");[b]//OK[/b]

pictureBoxAny.DataBindings.Add("Image",dataSet.Tables["MyTable"],"MyImageField");[b]//crash[/b]

I'm using sqlServer
 
You can't directly bind a BLOB field to a picture box, you need to convert it to a bitmap first:
Code:
Binding b = new Binding("Image",dataSet.Tables["MyTable"],"MyImageField");

b.Format += new ConvertEventHandler(b_Format);

pictureBox1.DataBindings.Add(b);

private void b_Format(object sender, ConvertEventArgs e)
{
	byte[] b = (byte[])e.Value;

	System.IO.MemoryStream ms = new System.IO.MemoryStream(b);

	Bitmap bmp = new Bitmap(ms);

	ms.Close();

	e.Value = bmp;
}
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top