Binding forecolour and ToolTip to a DataGrid

37 Views Asked by At

I have a DataGrid - there is

  1. A hidden column (SubjectFull) and a visible column with up to 60 characters of SubjectFull called Subject.

  2. A Column called Unread - this is an image in the case it has not been unread.

I can get a ToolTip to show the value of SubjectFull for just the visible part of the grid, but it messes up as soon as I scroll down.

For Each row As DataRowView In DGV.Items.OfType(Of DataRowView)
Dim DGRow As DevComponents.WPF.Controls.AdvGridRow = DGV.ItemContainerManager.ContainerFromItem(row, True)
Dim vTooltip As String = row("SubjectFull")
DGRow.ToolTip = vTooltip
Next

I'm trying to get a handle on this using

 Dim DGV As New DGVx
 With DGV
 .Name = "Inbox_DGV"
 .ContextMenu = ReturnContexMenu()
 End With
 RegisterControl(Inbox_Grid, DGV)
 Grid.SetRow(DGV, 1)
 Inbox_Grid.Children.Add(DGV)

 Dim vStyle As New Style(GetType(DevComponents.WPF.Controls.AdvGridRow))
 Dim vSetter As New Setter
 With vSetter
 .Property = DevComponents.WPF.Controls.AdvGridRow.IsSelectedProperty
 .Value = New Binding("Select") With {.Mode = BindingMode.TwoWay}
 End With
Dim vSetter2 As New Setter
With vSetter2
 .Property = DevComponents.WPF.Controls.AdvGridRow.ForegroundProperty
 .Value = New Binding("Unread") With {.Mode = BindingMode.TwoWay}

End With
vStyle.Setters.Add(vSetter)
vStyle.Setters.Add(vSetter2)
DGV.Resources.Add(GetType(DevComponents.WPF.Controls.AdvGridRow), vStyle)

The binding for the checkbox (select) works well, but I'm struggling to find a way to binding the string from the hidden column to the row and assigning a colour to a row where there is an image for unread.

Any pointers would be appreciated

Update - I now have ToolTips working and have another hidden integer field to denote 'Read' - If the value is 0 then the row needs to be red, otherwise default (or black)

 Dim vStyle As New 
Style(GetType(DevComponents.WPF.Controls.AdvGridRow))
Dim vSetter As New Setter
With vSetter
 .Property = DevComponents.WPF.Controls.AdvGridRow.IsSelectedProperty
 .Value = New Binding("Select") With {.Mode = BindingMode.TwoWay}
 End With

 Dim vSetter2 As New Setter
 With vSetter2
 .Property = DevComponents.WPF.Controls.AdvGridRow.ToolTipProperty
 .Value = New Binding("SubjectFull") With {.BindsDirectlyToSource = True}
 End With

 Dim vSetter3 As New Setter
 With vSetter3
 .Property = DevComponents.WPF.Controls.AdvGridRow.ForegroundProperty
 .Value = Brushes.Red '<--------This needs to be the value if FlagRead = 1
 End With
 With vStyle.Setters
 .Add(vSetter)
 .Add(vSetter2)
 .Add(vSetter3)
 End With
 DGV.Resources.Add(GetType(DevComponents.WPF.Controls.AdvGridRow), vStyle)
0

There are 0 best solutions below