假设,我在超网格中有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(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