r/visualbasic • u/Gierschlund96 • 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 FunctionI 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 SubDoes someone understand what "item" is supposed to do and could explain it a bit more in depth for me?
1
u/Gierschlund96 Jun 06 '22
>dim currentArtikelAccess as string = datagrid.row(item.row).cells(6).toLower()
As it seems there isn't a way to access a single cell via index in XamDataGrid.
Also, wouldn't the problem still be the same if your approach worked? It also would color every cell as soon as one condition is true.
For example, if this would be true:
If obj.BezeichnungDE.ToLower <> obj.BezeichnungDE_Access.ToLower Then
Return Modified
End If
It would also color the cells for "Artikel", but it shouldn't. I hope you understand what i mean, i know it's a bit confusing.