简体   繁体   中英

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

Lets say, I have NameColumn, IDColumn, DOBColumn in an ultragrid. Manually, I drag and drop the columns to different positions in 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.

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. 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

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

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