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
100
Icon and text in XamGrid cell
posted

Hi

 

I have a databound XamGrid with a text column. Depending on the values of the data, I need to display an icon together with the text in some rows, but just the text in other rows. I nearly have it working by handling the cellControlAttached event using the following code:

Private Sub grdListing_CellControlAttached(sender As Object, e As Infragistics.Controls.Grids.CellControlAttachedEventArgs)

        If e.Cell.Column.Key = "HoursRemaining" Then

            If e.Cell.Row.Data Is Nothing = False Then

                If CType(e.Cell.Row.Data, SchedulePeriod).IsLocked = 1 Then

                    Dim strImage As String = "/MEX;component/Images/Buttons/Lock.png"

                    Dim strControlText As String = "" _

                                & "" _

& ""

                    e.Cell.Control.ContentTemplate = MEXGridBindingManager.CreateEditorTemplate(strControlText)

                End If

            End If

        End If

    End Sub

Public Shared Function CreateEditorTemplate(pControlXAML As String) As DataTemplate

        Dim EditorTemp As New StringBuilder

        EditorTemp.Append("<DataTemplate ")

        EditorTemp.Append("xmlns='http://schemas.microsoft.com/winfx/2006/xaml/presentation' ")

        EditorTemp.Append("xmlns:ig='http://schemas.infragistics.com/xaml' ")

        EditorTemp.Append("xmlns:x='http://schemas.microsoft.com/winfx/2006/xaml' ")

        EditorTemp.Append("xmlns:local = 'clr-namespace:MEX;assembly=MEX'>")

        EditorTemp.Append(pControlXAML)

        EditorTemp.Append("</DataTemplate>")

        Return CType(XamlReader.Load(EditorTemp.ToString()), DataTemplate)

    End Function

 

This appears to work at first - one row shows the icon and the text, the rest of the rows show the text only and this is correct. However, each time I scroll up or down, the icon gets added to more and more rows, seemingly at random. The data hasn't changed so the icon shouldn't be added to any more rows.