ListBox.CellTypes.CheckBox - How to set focus?

Hi,

i have a Listbox and set the value via code. Sample (Listbox.Open-Event):

Me.AddRow("First row")
Me.AddRow("Second row")
Me.AddRow("Third row")

Me.CellTypeAt(1, 0) = ListBox.CellTypes.CheckBox
Me.CellTypeAt(2, 0) = ListBox.CellTypes.CheckBox

Me.CellCheckBoxStateAt(1, 0) = CheckBox.VisualStates.Checked
Me.CellCheckBoxStateAt(2, 0) = CheckBox.VisualStates.Checked

Sadly, the Checkboxes doesn’t have the blue, focus color. I only get the color after I selected the rows with the mouse or after scrolling. How can I get the same result in code?


This is unfortunately a timing issue. When the framework requests the checkboxes for the Listbox, the focus state must be incorrect. A workaround is to invalidate the Listbox after it has focus. This can be done a number of ways, including using the GotFocus event.

Sub GotFocus() Handles GotFocus
  me.Invalidate
End Sub
1 Like

You made my day. Thanks @Tim_Parnell