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
1330
Adding an image column to UltraGrid
posted

I require the need to add a column to the UltraGrid that can display an image in it's cells.

The UltraGrid is bound to a data table however the column I need to add is not part of the dataTable.  The column would be entirely fabricated on the front end. 

Also I would need to create this column and add it after the InitializeLayout event has been triggered and I'm not sure how to access the columns in code at this point. 

Any help would be greatly appreciated thank you!

Parents
No Data
Reply
  • 469350
    Offline posted

    Hi,

    You can add an unbound column to the grid using the Add method on the Columns collection.

    Why does it have to be added after InitializeLayout? In most cases, I would recommend adding the column inside the InitializeLayout event. But it's pretty much the same either way:


            private void ultraGrid1_InitializeLayout(object sender, Infragistics.Win.UltraWinGrid.InitializeLayoutEventArgs e)
            {
                UltraGridLayout layout = e.Layout;
                UltraGridBand band = layout.Bands[0];

                UltraGridColumn imageColumn = band.Columns.Add("My Image Column");
                imageColumn.DataType = typeof(Image);
                imageColumn.Style = Infragistics.Win.UltraWinGrid.ColumnStyle.Image;
            }

    Outside of InitializeLayout, you would just use grid.DisplayLayout instead of e.Layout.

     

    And then you would probably want to use the InitializeRow event to populate the image column with a value.

    [code]


            private void ultraGrid1_InitializeRow(object sender, InitializeRowEventArgs e)
            {
                if (e.Row.Cells.Exists("My Image Column"))
                {
                    e.Row.Cells["My Image Column"].Value = someImage;
                }
            }

    [/code

Children