I’m having a senior moment: how to I set the selection in the listbox and keep the selection color? My code is very simple:
dim oldListIndex as Integer = LBImapAccounts.ListIndex
LBImapAccounts.RemoveRow(oldListIndex)
LBImapAccounts.ListIndex = oldListIndex
LBImapAccounts.Refresh
RaiseEvent ImapAccountSelectionChanged LBImapAccounts.Cell(LBImapAccounts.ListIndex, 2)
The new row of the listbox is selected. But even with the refresh I don’t see the row selection color from the CellBackgroundPaint:
[code] dim col as color
if me.Selected(row) then
col = SelectedRowColor
globals.theErrorLog.LogItem CurrentMethodName
else
'draw alternativing background
end if
g.foreColor = col
g.fillrect 0, 0, g.width, g.height
return true[/code]
Does anyone have an idea why the SelectedRowColor isn’t shown?
I don’t know why Selected(row) doesn’t work, but I would try this first anyway:
[quote=171192:@Beatrix Willius]dim col as color
if row = me.ListIndex then
col = …[/quote]
Another thing: you will need to account for the case where the last row is removed or you will have an OutOfBoundsException on this line:[quote=171192:@Beatrix Willius]LBImapAccounts.ListIndex = oldListIndex[/quote]