Hello. I have three listboxes pulling data from a database. Listbox A holds the data, Listbox B holds the column header information and is located directly above Listbox A, and Listbox C holds the row header information and is located directly to the left of Listbox A. Listbox B and C have background paint to color the entire listbox. Listbox A has Mod 2 row shading. All three have return True on background paint to remove row selection highlighting. Listbox A can contain a lot of information, so both vertical and horizontal scrollbars exist.
I have two variables, selectedRow and selectedColumn. When a cell is selected in Listbox A, it updates these variables to the cell selected. If a row header is chosen in Listbox C, it updates selectedRow; and is a column header is chosen in Listbox B is updates selectedColumn.
For Listbox A during the background paint, it reads the selectedRow and selectedColumn variables and places a box/border around that cell. Every cell with a matching column gets a left and right border; every cell with a matching row gets a top and bottom border. For Listbox B, the matching column gets a left and right border; for Listbox C, the matching row gets a top and bottom border. It creates a bordered path to show which item a user chooses in a large matrix filled in Listbox A.
In the image above, the border is created correctly, but to the lower right you’ll see some artifacts left from a previous selection. This is one issue, and the other is sometimes during a selection, one of the borders won’t be entirely drawn. This happens intermittently, not with every new selection. It appears to be not clearing the background paint on every instance. If I scroll so the issue area is outside of the viewable listbox and return, it is corrected.
So is there something I’m doing incorrectly? Or is there a way to clear the listbox background paint (which I thought happened automatically) without clearing the listbox as a whole?
Listbox A CellBackgroundPaint code:
[code]If row Mod 2 = 1 Then
If row = selectedRow Then
If column = selectedColumn AND selectedColumn < me.ColumnCount Then
g.ForeColor = RGB(240,249,249) // light blue
g.FillRect(0, 0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,g.Width,0
g.DrawLine 0,g.Height-1,g.Width,g.Height-1
g.DrawLine 0,0,0,g.Height-1
g.DrawLine g.Width-1, 0, g.Width-1, g.Height-1
ElseIf column < selectedColumn AND selectedColumn < me.ColumnCount Then
g.ForeColor = RGB(240,249,249) // light blue
g.FillRect(0, 0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,g.Width,0
g.DrawLine 0,g.Height-1,g.Width,g.Height-1
Else
g.ForeColor = RGB(240,249,249) // light blue
g.FillRect(0, 0, g.Width, g.Height)
End
Else
If column = selectedColumn AND selectedColumn < me.ColumnCount AND row < selectedRow AND selectedRow < me.LastIndex +1 Then
g.ForeColor = RGB(240,249,249) // light blue
g.FillRect(0, 0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,0,g.Height-1
g.DrawLine g.Width-1, 0, g.Width-1, g.Height-1
Else
g.ForeColor = RGB(240,249,249) // light blue
g.FillRect(0, 0, g.Width, g.Height)
End
End
ElseIf row Mod 2 = 0 Then
If row = selectedRow Then
If column = selectedColumn AND selectedColumn < me.ColumnCount Then
g.ForeColor = RGB(255,255,255) // white
g.FillRect(0,0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,g.Width,0
g.DrawLine 0,g.Height-1,g.Width,g.Height-1
g.DrawLine 0,0,0,g.Height-1
g.DrawLine g.Width-1, 0, g.Width-1, g.Height-1
ElseIf column < selectedColumn AND selectedColumn < me.ColumnCount Then
g.ForeColor = RGB(255,255,255) // white
g.FillRect(0,0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,g.Width,0
g.DrawLine 0,g.Height-1,g.Width,g.Height-1
Else
g.ForeColor = RGB(255,255,255) // white
g.FillRect(0,0, g.Width, g.Height)
End
Else
If column = selectedColumn AND selectedColumn < me.ColumnCount AND row < selectedRow AND selectedRow < me.LastIndex +1 Then
g.ForeColor = RGB(255,255,255) // white
g.FillRect(0,0, g.Width, g.Height)
g.ForeColor = RGB(0,0,0) // black
g.DrawLine 0,0,0,g.Height-1
g.DrawLine g.Width-1, 0, g.Width-1, g.Height-1
Else
g.ForeColor = RGB(255,255,255) // white
g.FillRect(0,0, g.Width, g.Height)
End
End
End
If me.ScrollPosition <> lbRowHeader.ScrollPosition Then
lbRowHeader.ScrollPosition = me.ScrollPosition
End
If me.ScrollPositionX <> lbColumnHeader.ScrollPositionX Then
lbColumnHeader.ScrollPositionX = me.ScrollPositionX
End
Return True[/code]
Thanks,
- Jason