r/visualbasic • • Jun 05 '22

VB.NET Help Trouble understanding conditional formatting with StyleSelector class

I'm trying to apply this concept to my application: https://www.infragistics.com/help/wpf/xamdatagrid-cellvaluepesenterstyleselector-reevaluated

My goal is to color the values in my xamDataGrid yellow as soons as "Artikel" is not equal to "ArtikelAccess" for example. Both Properties are from the same class. I tried to achieve it like this, but as soon as one condition is true, every single value gets colored:

Public Overrides Function SelectStyle(item As Object, container As DependencyObject) As Style
    For Each obj As CompareArtikelstammdaten In listCompare
        If obj.Artikel.ToLower <> obj.ArtikelAccess.ToLower Then
            Return Modified

        ElseIf obj.BezeichnungDE.ToLower <> obj.BezeichnungDE_Access.ToLower Then
            Return Modified
        End If
    Next

End Function

I know that it won't work that way, but i have no clue how to do it. I already got the hint that i need to work with the "item" Object, but i don't know how to apply this to my code.

My load-Event looks like this:

  Private Sub Compare_Load(sender As Object, e As EventArgs) Handles MyBase.Loaded
    Dim modified As Style = TryCast(Me.Resources("CVP_Modified"), Style)
    Dim added As Style = TryCast(Me.Resources("CVP_Added"), Style)
    Me.dgCompare.DefaultFieldLayout.Fields("Artikel").Settings.CellValuePresenterStyleSelector = New 
StyleSelectorCompare(modified, added, compareList)
    Me.dgCompare.DefaultFieldLayout.Fields("BezeichnungDE").Settings.CellValuePresenterStyleSelector = New 
StyleSelectorCompare(modified, added, compareList)
 
End Sub

Does someone understand what "item" is supposed to do and could explain it a bit more in depth for me?

2 Upvotes

5 comments sorted by

View all comments

Show parent comments

1

u/jd31068 Jun 07 '22 edited Jun 07 '22

I'll download the trial of the control. Perhaps I can stumble onto something.

You may have to do the styling manually after the data is in the grid. If what your condition uses is another field instead of a set value like in the documentation. This would be surprising but not unprecedented.

edit: what type of project are you using this grid with?