I am using a timer to solve this problem. Start the timer using the ItemCheck event. Take action at the Timer Tick event.
This works whether the item is checked with a mouse click or by pressing the space bar. We will take advantage of the fact that an item that has just been verified (or not verified) is always the selected item.
The timer interval can be as low as 1. By the time the Tick event occurs, a new status of "Checked" will be set.
This VB.NET code shows the concept. There are many options you can use. You can increase the timer interval so that the user can change the status of the check by several elements before taking action. Then in the Tick event make a sequential pass of all
Items are listed or use the CheckedItems collection to take appropriate action.
This is why we first turned off the Timer in the ItemCheck event. Disable, then Enable, causes the interval period to restart.
Private Sub ckl_ItemCheck(ByVal sender As Object, _ ByVal e As System.Windows.Forms.ItemCheckEventArgs) _ Handles ckl.ItemCheck tmr.Enabled = False tmr.Enabled = True End Sub Private Sub tmr_Tick(ByVal sender As System.Object, _ ByVal e As System.EventArgs) _ Handles tmr.Tick tmr.Enabled = False Debug.Write(ckl.SelectedIndex) Debug.Write(": ") Debug.WriteLine(ckl.GetItemChecked(ckl.SelectedIndex).ToString) End Sub
Bob Ashcraft Apr 10 '15 at 2:16 2015-04-10 02:16
source share