2

I want to make a ListView that has small images, that was taken from a scanner, inside of the ListView. (I have the scanning script done, and it saves the scanned image under C:/Temp/*.jpg. )

What I'm having trouble with is, I want the scanned images to be displayed inside of the ListView and when you click an image in the ListView it displayed the full Image in the PictureBox.

An Image of what i'm talking about.(tried to post the image inside of this post but rep isn't high enough)

I was thinking about having the images' location stored inside of an List array like

List<string> fileLocationArray = new List<string>();
foreach () {
...
string fileLoc = (@"C:\temp\" + DateTime.Now.ToString("yyyy-MM-dd HHmmss") + ".jpeg");
fileLocationArray.Add(fileLoc);
...
}

Then displaying the images inside the ListView using the List array.

Keep in mind that I plan on uploading these images to an FTP server. That's why I wanted to use a List array.

one more thing, they will be picture of document, not photos, if that means anything to you.

Dan J
  • 16,319
  • 7
  • 50
  • 82
Throdne
  • 619
  • 2
  • 9
  • 27
  • 7
    WPF or WinForms? It really makes all the difference. – Ed S. Sep 22 '11 at 21:06
  • I would NOT use a listbox for that. I would use either a grid with only 1 column (the image column) or a listview with big icons and no text. in WPF you do have much more power and options than in Windows Forms. – Davide Piras Sep 22 '11 at 21:09
  • 1
    possible duplicate of [Creating a ListBox of images?](http://stackoverflow.com/questions/4205531/creating-a-listbox-of-images) – Davide Piras Sep 22 '11 at 21:12
  • Sorry, it was a miss type, It is a ListView and not ListBox (hope I corrected everything) And it's a Windows Form Application. – Throdne Sep 22 '11 at 21:43
  • Any particular reason for wanting to use ListView? (asking because your screenshot would make me suggest a ListBox) – C.Evenhuis Sep 23 '11 at 04:44

1 Answers1

2
**Fill ListView :**   
 For(int i=0; i<fileLocationArray.Count();i++)
    {
    System.Windows.Controls.Image imgControl=new System.Windows.Controls.Image();
    BitmapImage imgsrc = new BitmapImage();
   imgsrc.BeginInit();
   imgsrc.UriSource=fileLocationArray[i];
                    imgsrc.EndInit();
    imgControl.source=imgsrc;
    listView.Items.Add(imgControl);

    }

    **After filling ListView control  create event  listView SelectionChanged**
    **imgContolShow   // this control show selected image**

    void listw_SelectionChanged(object sender, SelectionChangedEventArgs e)
        {
           imgContolShow.Source = ((System.Windows.Controls.Image)listwiev.SelectedItem).Source;  
        }
Aca
  • 69
  • 2