Hi,
With the windows ultragrid there is a method to save and load the displaylayout that work like this:
this.DisplayLayout.LoadFromXml( fs, PropertyCategories.All ); this.DisplayLayout.SaveAsXml( fs, PropertyCategories.All );
What is the equivalent way of doing this with the webgrid? Basically I need to give the users of the web application I'm developing the ablity to show/hide columns in a grid, group and sort as they please, and then save off those settings so that they next time they load the grid the contents will be display layout will be the same.
In case anyone's interested, here's a basic example I slapped together that seems to work.You'll need to change it to save to a DB or whatever.
Partial Class _Default Inherits System.Web.UI.Page Private Sub Form1_Load(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles MyBase.Load If Not IsPostBack Then Dim dt As System.Data.DataTable = New System.Data.DataTable("Table1") dt.Columns.Add("Col1", GetType(String)) dt.Columns.Add("Col2", GetType(String)) dt.Columns.Add("Col3", GetType(String)) dt.Columns.Add("Col4", GetType(String)) dt.Columns.Add("Col5", GetType(String)) Dim random As Random = New Random() Dim i As Integer For i = 0 To 5 - 1 Dim rowdata(4) As String Dim j As Integer For j = 0 To 5 - 1 rowdata(j) = random.Next(1000).ToString() Next dt.Rows.Add(rowdata) Next Me.UltraGrid1.DataSource = dt Me.UltraGrid1.DataBind() End If End Sub Protected Sub SaveSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles SaveSettings.Click Dim gl As New GridLayout For Each c As Infragistics.WebUI.UltraWebGrid.UltraGridColumn In Me.UltraGrid1.DisplayLayout.Bands(0).Columns gl.add(New ColumnLayout(c.Header.Caption, c.Header.RowLayoutColumnInfo.OriginX)) Next Session("layout") = gl End Sub Protected Sub LoadSettings_Click(ByVal sender As Object, ByVal e As System.EventArgs) Handles LoadSettings.Click Dim gl As GridLayout = TryCast(Session("layout"), GridLayout) If Not (gl Is Nothing) Then Dim col As Infragistics.WebUI.UltraWebGrid.UltraGridColumn For Each cl As ColumnLayout In gl col = Me.UltraGrid1.Columns.FromKey(cl.Key) col.Move(cl.PositionIndex) Next End If End SubEnd ClassPublic Class ColumnLayout Public Sub New(ByVal key As String, ByVal index As Int32) Me.Key = key Me.PositionIndex = index End Sub Private m_Key As String Public Property Key() As String Get Return m_Key End Get Set(ByVal value As String) If (m_Key <> value) Then m_Key = value End If End Set End Property Private m_PositionIndex As Integer Public Property PositionIndex() As Integer Get Return m_PositionIndex End Get Set(ByVal value As Integer) If (m_PositionIndex <> value) Then m_PositionIndex = value End If End Set End PropertyEnd ClassPublic Class GridLayout Inherits CollectionBase Public Sub add(ByVal val As ColumnLayout) Me.List.Add(val) End SubEnd Class
I didn't end up handling the column order. However, I believe if you get/set these properties it will work:
ParentGrid.Columns.FromKey(key).Footer.RowLayoutColumnInfo.OriginX ParentGrid.Columns.FromKey(key).Header.RowLayoutColumnInfo.OriginX
How do you handle the changes in column order? Or do you?
Thanks,
Chris
No I didn't. Apparently I stumped the infragistics support people on this one. I ended up writing some code to enumerate all the columns in the grid, let them choose which ones to show and hide, and then saving that off to a database.
Did you ever find a solution for this problem?