How To: Sort C1FlexGrid With Auto Execute Query Off
While working in a LightSwitch application, you would often need to load Query result on a conditional basis. For instance, if you are creating a custom search screen with many optional parameters you may want to first specify search criteria and then issue the search at once. To control the loading of data into screens, you can uncheck Auto Execute Query option from the screen. However, this option has a limitation. With AutoExecute property off, Sorting is disabled. You can read a discussion thread in this given link. This limitation covers C1Flexgrid for LightSwitch application as well. However, with manual handling we can overcome this limitation to implement sorting. As workaround, you can force the query to execute by itself when the Column header is clicked. Following code block shows the required implementation.
Private Sub FlexibleCustomersGrid_Created()
' Execute the Query (Customers)
Me.Customers.Load()
Dim flex = Me.FindControl("C1FlexGrid")
AddHandler flex.ControlAvailable, Sub(s, e)
Dim _flex As C1.Silverlight.FlexGrid.C1FlexGrid
_flex = CType(e.Control, C1.Silverlight.FlexGrid.C1FlexGrid)
AddHandler _flex.MouseLeftButtonUp, Sub(sm, em)
If \_flex.HitTest(em.GetPosition(\_flex)).CellType = C1.Silverlight.FlexGrid.CellType.ColumnHeader Then
Me.Details.Dispatcher.BeginInvoke(Sub()
Me.Customers.Load()
End Sub)
End If
End Sub
End Sub
End Sub