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!
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
Thanks a lot. This worked perfectly.
The one thing I can't seem to do is to center the image.
I tried:
imageColumn.CellAppearance.TextHAlign = HAlign.Right;
imageColumn.CellAppearance.TextVAlign = VAlign.Middle;
and it did not seem to do the trick.
Hi Paul,
You are reading out the TextHAlign property of the CellAppearance property of the column. This will only return a value if you set one on that cell, which you apparently didn't.
You must either be using the default alignment, or you are setting the alignment one some other appearance, like on the Override for the band or layout, or via AppStylist.
The grid resolves the appearance of any given cell when the cell paints on the screen and it takes into account many appearance properties, application styling, etc. So what you want is not the property setting on the individual column's CellAppearance, but rather the resolved appearance. For that, you need a cell (a column is not enough). You do it using the ResolveAppearance method.
Dim cell As UltraGridCell = Me.UltraGrid1.Rows(0).Cells(0) Dim appData As AppearanceData = New AppearanceData() Dim appearancePropFlags As AppearancePropFlags = appearancePropFlags.TextHAlign cell.ResolveAppearance(appData, appearancePropFlags) Debug.WriteLine(appData.TextHAlign)
Mike,
I'm trying to do something a little unique. I am working on an export to Excel feature for our users. I need to translate the TextHAlign values to Excel constants. to do it, I'm trying to retrieve the current text alignment value for the column like this:
Select Case .Columns.Item ( arrColumnKeys(x) ).CellAppearance.TextHAlign
Case Infragistics.Win.HAlign.Right
numAlignment = ExcelFunctions.Excel_Constants.xlRight
Case Infragistics.Win.HAlign.Left
numAlignment = ExcelFunctions.Excel_Constants.xlLeft
Case Infragistics.Win.HAlign.Center
numAlignment = ExcelFunctions.Excel_Constants.xlCenter
Case Else
End Select
The only thing that executes is the "Case Else" path. what am I missing?
Thanks in advance,
Paul
Try:
imageColumn.CellAppearance.ImageHAlign = HAlign.Right;
imageColumn.CellAppearance.ImageVAlign = VAlign.Middle;