gchq
Well-known member
- Joined
- Dec 14, 2007
- Messages
- 168
- Programming Experience
- 10+
Hi there
I'm attempting to redraw the DisplayMember to red if certain criteria are met
So far I have (using a dynamic form, and a dynamic panel)
The list box is populated via a DataTable like this
... and the DrawItem event is called like this
The problems I am having are:-
1. The DisplayMember is showing as 'System.Data.DataRowView'
2. Can't find a way to get the selected row to paint in white not black
Other than that the desired effect of the red row is great - sigh!
Any assistance would be appreciated!
I'm attempting to redraw the DisplayMember to red if certain criteria are met
So far I have (using a dynamic form, and a dynamic panel)
VB.NET:
Dim RevenueNominalLB As New ListBox
With RevenueNominalLB
.Name = "RevenueNominalLB"
.Size = New Point(200, 100)
.Location = New Point(345, 60)
.DrawMode = DrawMode.OwnerDrawFixed
End With
AddHandler RevenueNominalLB.DrawItem, AddressOf listBox_DrawItem
vPanel.Controls.Add(RevenueNominalLB)
The list box is populated via a DataTable like this
VB.NET:
Private Sub RevenueNominalAddNew_Click(ByVal sender As Object, ByVal e As EventArgs)
Dim RevenueLB As ListBox = RFC(ReportForm, "RevenueListBox")
If RevenueLB.SelectedIndex = -1 Then
AppBox.Show("You must select a category, from the box on the left first!", MessageBoxButtons.OK, MessageBoxIcon.Exclamation)
Exit Sub
End If
NominalDataPopup()
If Not GenCode = 0 Then
Dim CatID As Integer = RevenueLB.SelectedValue
Dim NomCode As Integer = GenCode
Dim NomName As String = GenName
Dim vRows As Integer = RevenueNomDT.Rows.Count
Dim vLastInt As Integer = 0
If vRows > 0 Then
vLastInt = RevenueNomDT.Compute("MAX(Position)", Nothing) + 1
End If
For Each Column As DataColumn In RevenueNomDT.PrimaryKey
Column.AutoIncrement = True
Column.AutoIncrementStep = 1
Column.AutoIncrementSeed = vLastInt + 1
Next
Dim RevenueNomCB As CheckBox = RFC(ReportForm, "RevenueNomCB")
Dim vNegValue As Integer = 0
If RevenueNomCB.Checked = True Then
vNegValue = 1
End If
Dim vNewRow As DataRow = RevenueNomDT.NewRow
vNewRow("CatID") = CatID
vNewRow("NomName") = GenName
vNewRow("NomCode") = GenCode
vNewRow("Position") = vLastInt
vNewRow("NegValue") = vNegValue
RevenueNomDT.Rows.Add(vNewRow)
Dim vDV As New DataView(RevenueNomDT)
vDV.Sort = "Position"
RevenueNomDT = vDV.ToTable
vDV = Nothing
Dim RevenueNomLB As ListBox = RFC(ReportForm, "RevenueNominalLB")
RevenueNomLB.DataSource = RevenueNomDT
RevenueNomLB.DisplayMember = "NomName"
RevenueNomLB.ValueMember = "ID"
RevenueNomCB.Checked = False
End If
End Sub
... and the DrawItem event is called like this
VB.NET:
Private Sub listBox_DrawItem(ByVal sender As Object, ByVal e As DrawItemEventArgs)
e.DrawBackground()
Dim myBrush As Brush = Brushes.Black
For Each row As DataRow In RevenueNomDT.Rows
Dim vNeg As Integer = row("NegValue")
Dim vPos As Integer = row("Position")
If vNeg = 1 Then
Select Case e.Index
Case vPos
myBrush = Brushes.Red
End Select
End If
e.Graphics.DrawString(sender.Items(e.Index).ToString(), e.Font, myBrush, e.Bounds, StringFormat.GenericDefault)
e.DrawFocusRectangle()
Next
End Sub
The problems I am having are:-
1. The DisplayMember is showing as 'System.Data.DataRowView'
2. Can't find a way to get the selected row to paint in white not black
Other than that the desired effect of the red row is great - sigh!
Any assistance would be appreciated!