I want to be able to allow the user to move columns around then automatically save the layout, next time they open the program, automatically load the saved layout.
I have looked through the forums for some hint as to how to do it. does anyone have any sample code on how to save and load grid layouts?
vb.net would be preferred, but C#, I cna convert.
Thanks
There is a section in the help titled Save and Load a Layout to a File which shows code for saving and loading via an xml file. You can also save as a binary if you prefer that. I send them off into a SQL Server table myself. I think there may be an exmaple of that somewhere also if thats what you want to do.
Nick
wow, that was easier then I thought. I guess I was using the wrong keyword...
My question now is, besides mouse donw/up event. Doesn the grid have an event that fires when a column header is moved?
So far I can't find one.
NOTE: Found the property to handle this. thanks
The grid has BeforeColPosChanged and AfterColPosChanged events which get fired when column headers are moved (i.e., when you rearrange column order). These events are also fired when you resize the width of a column.
That is the one I am using...
AfterColPosChanged.
In that event, depending upon which tab is active, which determines how the grid is setup. I use the following code.
' Following code saves the ultraGrid1's layout to a file in xml format.
Dim fs As System.IO.FileStream = Nothing
If _currentGrid.ToString = "1" Then
XML_LAYOUT_FILE_PATH += ".\SCLIntraRecipientGrid.xml"
Else
XML_LAYOUT_FILE_PATH += ".\SCLIntraLocationGrid.xml"
Try
' Open a new file to save the layout to.
Catch exc As Exception
Return
End Try
Hi,
Why not just save the layout once when the form closes, like in the Form_Closed event? It's a bit inefficient to keep saving and re-saving the layout every time a column is moved. :)
i would, except it is part of a custom control... And other then the dispose event. I dont have a form.close
Even if you don't have a form_closed event, you must have a form somehow. Here is what I did:
In the Layout event, try to save the form in a property (ContainerForm):
{
}
in the property, listen to the form_closed event:
[DesignerSerializationVisibility(DesignerSerializationVisibility.Hidden)]
get
set
m_ContainerForm.FormClosed -= new FormClosedEventHandler(m_ContainerForm_FormClosed);
if (m_ContainerForm != null)
in the event handler save the layout:
SaveLayout();
It's no big deal to do it on every column change. But if you are concerned about efficiency, what I would do is add a method to the usercontrol to save the grid layout, and then call that from the form that the usercontrol is on. :)