Binding a PictureBox Control to A ImageList - what field to bind to?

S

Steph

I am trying to bind a simple ImageList Control to a PictureBox. I
can't seem to find in documentation, or through trial and error, the
right ImageList data member to bind to. Nothing seems to work. The
code below attempts to bind the PictureBox "pbMain" to the ImageList
"ilPics" which is successfully loaded with images from a test
directory. The question mark in the "DataBindings.Add" method
indicates the parameter in question. Has anyone else successfully
done this and could you help me out?

private void PicView_Load(object sender, System.EventArgs e)
{
// Get all files in sample directory
DirectoryInfo dirImages = new DirectoryInfo("C:\\data\\All
Images\\image.assets");

foreach (FileInfo file in dirImages.GetFiles())
{
if (file.Extension == ".jpg")
{
Image myImage = Image.FromFile(file.FullName);
ilPics.Images.Add(myImage);
}
}

// bind to picture box
pbMain.DataBindings.Add("Image",ilPics, ?);

}
 
B

Ben S. Stahlhood II

Steph,

The first parameter is the Property on the current object, the second is the
objec to bind to, and the third is the property name on the object you are
binding to...

So in your case the parmamter would need to be "Images", which will not work
or does not make sense. I am not sure what you are trying to accomplish,
but this does not seem to be a solution that will work out the way you would
like it to...

If you explain a little more on what you are trying to accomplisth, I might
be able to help you more

Regards,
Ben S. Stahlhood II
 
S

Steph

Sure. My requirement is to display a set of images from any directory
on a drive. (Hard coded for simplicity in this example.) I need to
display those images, one at a time in a windows form and give the
user the ability to scroll back and forth through the images. The
PictureBox is an appropriate control for display, the ImageList an
appropriate control to store the collection of images, and data
binding seemed to be a good control mechanism. I am attempting to
bind the first image in the ImageList to the PictureBox. I have two
buttons which will move through the images using the BindingContext.
Thanks. Steph.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top