简体   繁体   English

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

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

Lets say, I have NameColumn, IDColumn, DOBColumn in an ultragrid.可以说,我在一个超网格中有 NameColumn、IDColumn、DOBColumn。 Manually, I drag and drop the columns to different positions in ultragrid.我手动将列拖放到 Ultragrid 中的不同位置。

DataTable dt = ultragrid.DataSource as DataTable;

When I checked the datasource, column names is in the same order as before, data source is not reflecting the current UI column order.当我检查数据源时,列名与以前的顺序相同,数据源没有反映当前的 UI 列顺序。

Any help would be great.任何帮助都会很棒。

You are correct.你是对的。 Changing the order of the columns of the UltraGrid does NOT change the order of the bound data source.更改 UltraGrid 列的顺序不会更改绑定数据源的顺序。 Assuming you're asking this question because you wish to persist the layout of the grid, create a method similar to the following and call it from several different events that change the layout of your grid.假设您问这个问题是因为您希望保留网格的布局,请创建一个类似于以下内容的方法,并从更改网格布局的多个不同事件中调用它。

    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

When you re-open your grid, you can then call the following method to retrieve the previously saved grid layout:当您重新打开网格时,您可以调用以下方法来检索以前保存的网格布局:

    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