'宣言 Public Property FieldDisplayOrderComparer As IComparer(Of FieldItem)
public IComparer<FieldItem> FieldDisplayOrderComparer {get; set;}
フィールドをカスタムな順序で表示するために、フィールドを表示する順序を決定する FieldChooser の比較子を指定できます。
Imports Infragistics.Windows Imports Infragistics.Windows.Controls Imports Infragistics.Windows.Editors Imports Infragistics.Windows.DataPresenter Imports Infragistics.Windows.DataPresenter.Events Private Sub Dp_FieldChooserOpening(ByVal sender As Object, ByVal e As FieldChooserOpeningEventArgs) Dim fieldChooser As FieldChooser = e.FieldChooser ' You can use the FieldDisplayOrderComparer property to display fields ' in a custom order instead of the default alphabetical order. Set ' it to an object that implements IComparer<Field> and has the custom ' comparison logic that conveys the order of fields. fieldChooser.FieldDisplayOrderComparer = New CustomFieldOrderComparer() End Sub Private Class CustomFieldOrderComparer Implements IComparer(Of FieldItem) Private Function Compare(ByVal x As FieldItem, ByVal y As FieldItem) As Integer Implements IComparer(Of FieldItem).Compare ' Create a list of fields in the order in which you want to display ' them in the field chooser. Dim fieldsInOrder() As String = _ { _ "ID", _ "Product_Name", _ "Price", _ "Quantity", _ "Total", _ "Discount", _ "Net_Total" _ } ' Then use the indexes into the list for comparison. This effectively ' will cause the field chooser to display the fields in the same ' order as in the list above. Dim xIndex As Integer = Array.IndexOf(fieldsInOrder, x.Name) Dim yIndex As Integer = Array.IndexOf(fieldsInOrder, y.Name) Return xIndex.CompareTo(yIndex) End Function End Class
using Infragistics.Windows; using Infragistics.Windows.Controls; using Infragistics.Windows.Editors; using Infragistics.Windows.DataPresenter; using Infragistics.Windows.DataPresenter.Events; private void dp_FieldChooserOpening( object sender, FieldChooserOpeningEventArgs e ) { FieldChooser fieldChooser = e.FieldChooser; // You can use the FieldDisplayOrderComparer property to display fields // in a custom order instead of the default alphabetical order. Set // it to an object that implements IComparer<Field> and has the custom // comparison logic that conveys the order of fields. fieldChooser.FieldDisplayOrderComparer = new CustomFieldOrderComparer( ); } private class CustomFieldOrderComparer : IComparer<FieldItem> { public int Compare( FieldItem x, FieldItem y ) { // Create a list of fields in the order in which you want to display // them in the field chooser. string[] fieldsInOrder = new string[] { "ID", "Product_Name", "Price", "Quantity", "Total", "Discount", "Net_Total" }; // Then use the indexes into the list for comparison. This effectively // will cause the field chooser to display the fields in the same // order as in the list above. int xIndex = Array.IndexOf( fieldsInOrder, x.Name ); int yIndex = Array.IndexOf( fieldsInOrder, y.Name ); return xIndex.CompareTo( yIndex ); } }