Click here to Skip to main content
15,886,840 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hi guys,

I'm new to windows based applications.

i have created one application in which i have to upload some images and
these images should be display in a grid.

In this, i'm using entity to save/fetch data.

i successfully saved the images in the database, but now i want to fill it
in a gridview and imagelist.

What I have tried:

i have fetched some images in added in picturebox.
But it is showing only one pic.

NPS_BroadcastingEntities1 nps = new NPS_BroadcastingEntities1();
var item = nps.tbl_ScreenImages.Where(a => a.RecID == 1).SingleOrDefault();
byte[] arr = item.ImgNps;
MemoryStream ms = new MemoryStream(arr);
pictureBox1.Image = Image.FromStream(ms);


i want to fill all the images in the grid.

and in the second winform, i have to display all the images, one by one.

Can any one plz help me.



Thanks
Posted
Updated 31-May-16 0:25am

private ImageList FetchAllImages()
{
    ImageList imglist = new ImageList();
    string qry = "Select * from tbl_ScreenImages";
    SqlCommand cmd = new SqlCommand(qry, conn);
    SqlDataAdapter da = new SqlDataAdapter(cmd);
    DataTable dt = new DataTable();
    da.Fill(dt);
    foreach(DataRow dr in dt.Rows)
    {
        byte[] arr = (byte[])dr["imgNps"];
        MemoryStream ms = new MemoryStream(arr);
        imglist.Images.Add(Image.FromStream(ms));
    }

    return imglist;
}


timer_click
int i = 0;
private void timer1_Tick(object sender, EventArgs e)
{
    i++;
    imageList1 = FetchAllImages();
    int imgCount = imageList1.Images.Count;
    if (i % 2 != 0)
    {
        if (i < imgCount)
        {
            pictureBox1.Image = imageList1.Images[i];
        }
        else
        {
            i = 0;
        }
        Thread.Sleep(500);
    }
    else
    {
        if (i < imgCount)
        {
            pictureBox1.Image = imageList1.Images[i];
        }
        else
        {
            i = 0;
        }
        Thread.Sleep(500);
    }
}


Form1_load()
timer1.start();
 
Share this answer
 

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