[Solved, below. Posted in case anyone else has this problem.]
I have a form with a datarepeater ('DR' henceforth) that displays several rows. One of the controls in the DR is a checkbox. When the user clicks the ckeckbox in one of the rows, that row becomes the current record, the Checkbox_click event is raised, and code in that event's handler uses DR.CurrentItemIndex to process the current record.
When the form is the Windows active form (has the focus), this works perfectly. Hover over a checkbox (not the current item) and it turns blue, click it and its row becomes current and the checkbox toggles.
The problem occurs when the form is not the Windows active form. For example, click on the Desktop, then hover the mouse over a checkbox on the form (not the current item) and click, the DR CurrentItemIndex does not change.
I've traced some of the raised events to see what happens. Here, 'a' is the current item, click on the row 'b' checkbox:
If the Form has the focus:
1. Checkbox Hover (prior to click)
2. DR DrawItem (a)
3. DR DrawItem (b)
4. DR CurrentItemChanged (to b)
5. Checkbox click
If the Form does NOT have the focus:
1. CheckBox Hover (prior to click)
2. Form activated
3. Checkbox click
The DR CurrentItemIndexChanged event is never raised.
Because code in the Checkbox_click handler uses DR.CurrentItemIndex, in the second case above it uses the wrong index and so the program malfunctions.
How can I get the DR to act consistently? Or, as a workaround, how can the Checkbox_click handler get the correct ItemIndex?
[Solution] In the ck_MouseHover event handler:
Me.Focus
(Such a long time spent on such an easy solution!)