繁体   English   中英

重新排列超网格中的列,不会反映在数据源中(Winforms、Infragistics)

[英]Rearranging columns in ultragrid, doesn't reflect in the datasource (Winforms, Infragistics)

可以说,我在一个超网格中有 NameColumn、IDColumn、DOBColumn。 我手动将列拖放到 Ultragrid 中的不同位置。

DataTable dt = ultragrid.DataSource as DataTable;

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

任何帮助都会很棒。

你是对的。 更改 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("MyCustomPath\Layouts\") Then
            IO.Directory.CreateDirectory("MyCustomPath\Layouts\")
        End If

        Dim oFileLayout As New IO.FileStream("MyCustomPath\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 = "MyCustomPath\Layouts\" & ChildNode & ".layout"
        If IO.File.Exists(strFile) Then
            ug.DisplayLayout.Load(strFile)
        End If
    End Sub

暂无
暂无

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM