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



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

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

最新更新