Handle DoubleClick Event in Silverlight4 using C1TapHelper
One of the customers requested for displaying the contents of a row in C1DataGrid when it is double clicked in Silverlight 4. As is known that Silverlight 4 does not have a Double click event but the same can be easily implemented in Silverlight 5 using the 'ClickCount' event data property of the MouseButtonEventArgs class. C1TapHelper is a cross-platform helper for listening to tapped and double-tapped events which could be used in your Silverlight 4 applications by just adding the reference to the assembly 'C1.Silverlight.dll'. This blog implements the customer's requirement using the C1TapHelper class's DoubleTapped event.
Binding C1DataGrid to a DataTable
Dim dt As New DataTable()
dt.Columns.Add("CurrencyCode", GetType(Integer))
dt.Columns.Add("Industry", GetType(String))
dt.Columns.Add("Market", GetType(String))
dt.Columns.Add("Sector", GetType(Integer))
dt.Columns.Add("Total", GetType(Decimal))
dt.Columns.Add("SecurityType", GetType(String))
dt.Rows.Add(1, "Ind1", "M1", 56, Nothing, "type1")
dt.Rows.Add(2, "Ind2", "M2", 65, Nothing, "type2")
dt.Rows.Add(3, "Ind3", "M3", 54, 30045.005, "type3")
dt.Rows.Add(4, "Ind4", "M4", 78, 40045.47, "type4")
dt.Rows.Add(5, "Ind5", "M5", 21, 50340.475, "type5")
dt.Rows.Add(6, "Ind6", "M6", 45, 600895.42, "type6")
dt.Rows.Add(7, "Ind7", "M7", 59, 70048.78, "type7")
dt.Rows.Add(8, "Ind8", "M8", 77, 80085.9, "type8")
dt.Rows.Add(9, "Ind9", "M9", 62, 90076.78, "type9")
Dim dv As C1.Silverlight.Data.DataView = New DataView(dt)
datagrid.ItemsSource = dv
Handle the DoubleTapped Event
Private Sub datagrid_LoadedRowPresenter(sender As Object, e As C1.Silverlight.DataGrid.DataGridRowEventArgs)
'Using the C1TapHelper class
Dim double_tap As New C1.Silverlight.C1TapHelper(e.Row.Presenter)
AddHandler double\_tap.DoubleTapped, AddressOf double\_tap_DoubleTapped
End Sub
'Handle the Double Click event to display Row content
Private Sub double\_tap\_DoubleTapped(sender As Object, e As C1.Silverlight.C1TappedEventArgs)
Dim data As String = Nothing
For I As Integer = 0 To datagrid.Columns.Count - 1
Dim nulldata As Object = DirectCast(datagrid.Selection.SelectedRows(0).DataItem, C1.Silverlight.Data.DataRowView).GetData(I)
If nulldata Is Nothing Then
data = (data & Convert.ToString("null")) + " "
Else
data = (data & DirectCast(datagrid.Selection.SelectedRows(0).DataItem, C1.Silverlight.Data.DataRowView).GetData(I).ToString()) + " "
End If
Next
C1.Silverlight.C1MessageBox.Show(Convert.ToString("Row Data : " & vbLf) & data)
End Sub
and we are done !! :) Download Sample VB Download Sample CS