重新排列Ultragrid中的列,不反映在数据源中(Winforms,Infragistics)

问题描述 投票:1回答:1

假设,我在超网格中有NameColumn,IDColumn,DOBColumn。手动将列拖放到超网格中的不同位置。

DataTable dt = ultragrid.DataSource as DataTable;

当我检查数据源时,列名与以前的顺序相同,数据源未反映当前UI列的顺序。

任何帮助都会很棒。

c# winforms c#-4.0 infragistics
1个回答
0
投票

您是正确的。更改UltraGrid的列顺序不会更改绑定数据源的顺序。假设您要问这个问题是因为您希望保留网格的布局,请创建类似于以下内容的方法,并从多个更改网格布局的不同事件中调用它。

    Public Sub SaveGridLayout(ByRef UltraGrid As UltraGrid, ByVal ParentNode As String, ByVal ChildNode As String)
        If IsNothing(ChildNode) Then Exit Sub
        If ChildNode.Length = 0 Then Exit Sub

        If Not IO.Directory.Exists(MDI.DataPath & "Layouts\") Then
            IO.Directory.CreateDirectory(MDI.DataPath & "Layouts\")
        End If

        Dim oFileLayout As New IO.FileStream(MDI.DataPath & "Layouts\" & ChildNode & ".layout", IO.FileMode.Create)
        oFileLayout.Seek(0, IO.SeekOrigin.Begin)
        UltraGrid.DisplayLayout.Save(oFileLayout, Infragistics.Win.UltraWinGrid.PropertyCategories.All)
        oFileLayout.Close()
    End Sub

重新打开网格时,可以调用以下方法来检索以前保存的网格布局:

    Public Sub LoadGridLayout(ByRef ug As UltraGrid, ByVal ParentNode As String, ByVal ChildNode As String, Optional FormatDate As Boolean = True)
        Dim strFile As String = MDI.DataPath & "Layouts\" & ChildNode & ".layout"
        If IO.File.Exists(strFile) Then
            ug.DisplayLayout.Load(strFile)
        End If
    End Sub
© www.soinside.com 2019 - 2024. All rights reserved.