Thursday, February 3, 2011

Double Click for ListBox - Silverlight

 

Following is the code that I follow for getting my code working for the doubleclick event for a listbox event in silverlight

First I declare 2 field/variables at Form level so that they are accessible through out the form/silverlight page like this:

Dim t1 As New DateTime
Dim t2 As New Integer

Then I write the following code in the MouseUp or left mouse up event.

Dim n As New DateTime
        n = Now
        Dim c As Double = DateDiff(DateInterval.Second, t1, n)
        If DateDiff(DateInterval.Second, t1, n) < 1 Then
            If n.Millisecond - t1.Millisecond < 100 Then
                If t2 = ListBox1.SelectedIndex Then
                    'Double click event code here
                    MessageBox.Show("Working")
                Else
                    'Single Click event code here
                End If
            End If
        End If
        t1 = Now
        t2 = ListBox1.SelectedIndex

It works well, I use it.

No comments:

Post a Comment