Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
120
Http Image in UltraGrid
posted

Hi

Is there a way to display an image in an ultragrid cell from an http source eg http://site/image.jpg? Basically I have the image paths in my database and just want to load or display the images into the data grid.

Cheers

Dave

  • 29105
    Offline posted

    Hello,

    This really depends on how you have your grid setup. eg. either has a image field, or some external control rendering the image. 

    You can use a PictureBox and then embed that into the cells of the Image column or assign the value of the cells in perhaps the InitializeRecord event.

    https://stackoverflow.com/questions/4071025/load-an-image-from-a-url-into-a-picturebox

    Since the underlying property would most likely be a String (urls) you could consider displaying an unbound field that is of type Image and hide the URL field and when adding images only show the Image Field. 

    Assigning an image to a cell/column can be done by either hosting a control, like a PictureBox or by setting the Cell's value to be a new Image if you decide not to use a PictureBox. I believe there is a ImageLocation property you can set directly to a URL. Otherwise you will have to create a Stream and assign the cell value. You just have to set the CellAppearance.ImageBackground property to a new image.

    private void ultraGrid1_InitializeRow(object sender, Infragistics.Win.UltraWinGrid.InitializeRowEventArgs e)
    {
    
    using (var response = request.GetResponse())
    using (var stream = response.GetResponseStream())
    {
    // Check if this is data row - if you have summaries, groups...
    if (e.Row.IsDataRow)
    {
    // Create an image from the path string in the "Path" cell
    Image image = Bitmap.FromFile(e.Row.Cells["Path"].Text);
    
    // Or Put the image in the "Image" cell
    e.Row.Cells["Image"].Value = Bitmap.FromStream(stream);
    pictureBox1.Image = Bitmap.FromStream(stream);
    } 
    }
    }