In the InitializeLayout event of a grid, I set the e.Layout.Bands[bandName].Columns[columnName].Width of each column, and I set
e.Layout.Override.RowSizing = RowSizing.AutoFree; e.Layout.Override.CellMultiLine = DefaultableBoolean.True;
The text automatically wraps if it is not wide enough to fit in a column, and the row height adjusts automatically. However the text in all cells is aligned to the top of the cell. I think the grid would look a lot better if all text were centered vertically instead.
I have tried setting
e.Layout.Override.CellAppearance.TextVAlign = VAlign.Middle;
and several variants of this, but I have been unable to find a way to make the text in all cells center vertically, although the text in some of them, for example in the Date columns, does do so. There must be a way, but what is it?
Hi Mike,
Thank you for this solution.
But when I put .Style = ColumnStyle.Integer is don't work
Francois
Thanks Mike! This solution totally works. I needed to sort the content in a merged cell vertically centered and this code snippet you provided did it!
Thank you very much for your help. You're awsome.
Hi Steve,
Sure, here's a VB version of the same code:
Public Class MiddleAlignDrawFilter Implements IUIElementDrawFilter Public Function DrawElement(drawPhase As Infragistics.Win.DrawPhase, ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Boolean Implements Infragistics.Win.IUIElementDrawFilter.DrawElement Dim cell As UltraGridCell = drawParams.Element.GetContext(GetType(UltraGridCell)) If Not cell Is Nothing AndAlso cell.Column.Key = "String 1" Then drawParams.AppearanceData.TextVAlign = VAlign.Middle End If Return False End Function Public Function GetPhasesToFilter(ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Infragistics.Win.DrawPhase Implements Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter If TypeOf drawParams.Element Is EditorWithTextDisplayTextUIElement Then Return DrawPhase.BeforeDrawForeground End If Return DrawPhase.None End Function End Class
You assign the DrawFilter to the grid like this:
Private Sub Form1_Load(sender As System.Object, e As System.EventArgs) Handles MyBase.Load Me.UltraGrid1.DrawFilter = New MiddleAlignDrawFilter() End Sub
I'm having the same issue. Could you please provide the code in VB? I'm new to Infragistics and don't know how to convert your code to VB. Thank you