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
1105
Stumped By Image size
posted

Using the Infragistics grid bound to a data table.  The data table has two columns:

1) Competitor Item: string

2) Image 1: System.Drawing.Image

Not every row has a value for the Image 1 column, but those that do have a value that is a System.Drawing.Image.  Sizes of the images are all over the map (310x182, 960x720, etc)

The column is set to Style= Image  The column cell appearance is set to Center and MIddle.

When I bind the data, I can see my an image in the cell for rows that have an image.  However, the image itself is very tiny and always stuck in the upper left corner, regardless of how i size the column or row.

Any thoughts?

Parents
No Data
Reply
  • 469350
    Verified Answer
    Offline posted

    Hi,

    The grid doesn't make any attempt to size the rows based on the image. If you want to do that, you will need to set the height of the row yourself.

    I assume, since some of your rows have images and others don't, that you want the row height to be variable. You wouldn't want to waste space making all of the rows the same height when some don't have an image.

    So if that assumption is correct, you could do something like this:



            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridOverride ov = layout.Override;

                // Let each row in the grid be a different height.
                ov.RowSizing = RowSizing.AutoFree;
            }

            private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                Image image = e.Row.Cells["Image 1"].Value as Image;
                if (image != null)
                {                
                    e.Row.Height = Math.Max(image.Height, e.Row.Height);
                }
            }

    The grid will maintain the aspect ration of the image by default, so this code will work okay as long as your images are not wider than the column. You might want to set the Width on the column to the width of the widest image first.

Children