We have an Ultragrid using the CardView feature, now business wants to have different color for the CardView Caption and also add some icon to some of the CardView Captions.
Is it possible to do that?
So far, from my research on this site, it is a text only property and can have only two colors, one for the regular CardView Caption, and the other for the Active CardView Caption.
Works now, looks like my Card_Caption_Images_DrawFilter code was messing up the image.
Thanks for the samples. When I put those codes inside my program, the image is blank. Am I doing something wrong? I am using Infragistics 2008 version. I am sure my imaglist is full of images.
Hello ,
Thank you for the provided code snippet. I have reviewed it and I notice that you are getting ImageUIElement of CardCaptionUIElement, in order to set image in the caption. By default CardCaptionUIElement has haven’t ImageUIElement. So you should add ImageUIElement to CardCaptionUIElement. You could add ImageUIElement to CardCaptionUIElement in DrawFilter implementation, but it is better approach to use CreationFilter do add UIElement. I have implemented my suggestion (my implementation is consistent with your code) in a small sample. Please run the sample and let me know if this is what you are looking for.
Please let me know if you have any further questions.
Here is the outcome that I try to accomplish, you can see inside the CardView Caption, I need a text and next to it an icon.
Here is what I tried, but I realize that drawParams.Element of one CardView Caption can only be one specific type, either text or image. Probably cannot be both. Unless you have a mixed text/image type.
Public Class Card_Caption_Images_DrawFilter Implements IUIElementDrawFilter #Region "Implementation of IUIElementDrawFilter" Public Function GetPhasesToFilter(ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Infragistics.Win.DrawPhase Implements Infragistics.Win.IUIElementDrawFilter.GetPhasesToFilter 'Check for a CardCaptionUIElement If TypeOf drawParams.Element Is CardCaptionUIElement Then 'Return BeforeDrawForeground so we can intercept the element Return DrawPhase.BeforeDrawBackColor ElseIf TypeOf drawParams.Element Is ImageUIElement Then If Not drawParams.Element.GetAncestor(GetType(CardCaptionUIElement)) Is Nothing Then 'Return BeforeDrawImage so we can intercept the image before it is drawn. Return DrawPhase.BeforeDrawImage End If Else
Return DrawPhase.None End If End Function Public Function DrawElement(drawPhase As Infragistics.Win.DrawPhase, ByRef drawParams As Infragistics.Win.UIElementDrawParams) As Boolean Implements Infragistics.Win.IUIElementDrawFilter.DrawElement Dim objImageUIElement As ImageUIElement Dim objGrid As UltraGrid Dim objRow As UltraGridRow Dim objImageList As ImageList Dim objImage As Image Select Case drawPhase Case Infragistics.Win.DrawPhase.BeforeDrawBackColor 'Get the row we are dealing with. This is to we can determine the 'color based on the data in the row. objRow = TryCast(drawParams.Element.GetContext(GetType(UltraGridRow)), UltraGridRow) If objRow IsNot Nothing Then If CBool(objRow.Cells(35).Value) Then drawParams.AppearanceData.ForeColor = Drawing.Color.DarkBlue drawParams.AppearanceData.BackColor = System.Drawing.Color.FromArgb(CType(CType(215, Byte), Integer), CType(CType(235, Byte), Integer), CType(CType(255, Byte), Integer)) Else drawParams.AppearanceData.ForeColor = System.Drawing.Color.FromArgb(CType(CType(112, Byte), Integer), CType(CType(112, Byte), Integer), CType(CType(112, Byte), Integer)) drawParams.AppearanceData.BackColor = Drawing.Color.LightGray End If End If Case drawPhase.BeforeDrawImage 'Get the ImageUIElement objImageUIElement = TryCast(drawParams.Element, Infragistics.Win.ImageUIElement) 'Get a reference to the grid control. This is only necessary in 'order to get the ImageList. If you are using images from somewhere 'else, you do not need this line. objGrid = TryCast(objImageUIElement.Control, UltraWinGrid.UltraGrid) objImageList = objGrid.ImageList 'Get the row we are dealing with. This is to we can determine the 'image based on the data in the row. objRow = TryCast(drawParams.Element.GetContext(GetType(UltraGridRow)), UltraGridRow) 'Use the "Key" Column to get an image from the imagelist. objImage = objImageList.Images(0) 'Assign the Image to the ImageUIElement objImageUIElement.Image = objImage 'Return False so the grid will just go right along and draw the new image. End Select Return False End Function#End RegionEnd Class