-
Using a layout file to preserve user changes [Janus GridEX WinForms Control v3.5 for .NET]
This tutorial is intended to show you how to use a layout file to preserve Schedule control settings. Using a layout file you could be able to preserve even the changes to the layout made by the user.
Follow these steps to use a layout file at run time:
1) Define the layout at design time and then save it clicking in the "Save Layout File" button that is found in the "Layout Manager" tab of the Schedule control designer.
2) In the Load event of the form, load the layout from a file using the LoadLayoutFile method of the Schedule.
In VB:
Private Sub LoadLayout()
Dim layoutDir As String = "C:\ScheduleLayout.xml"
Dim layoutStream As FileStream = New FileStream(layoutDir, FileMode.Open)
Schedule1.LoadLayoutFile(layoutStream)
layoutStream.Close()
End Sub
In C#:
private void LoadLayout()
{
string layoutDir = @"C:\ScheduleLayout.xml";
FileStream layoutStream;
FileInfo fInfo = new FileInfo(layoutDir);
if (fInfo.Exists)
{
layoutStream = new FileStream(layoutDir, FileMode.Open);
schedule1.LoadLayoutFile(layoutStream);
layoutStream.Close();
}
}
3) (Optional) To preserve user changes to the layout, update the layout before it is changed in the CurrentLayoutChanging event of the Schedule.
In VB:
Private Sub Schedule1_CurrentLayoutChanging(ByVal sender As System.Object, ByVal e As System.ComponentModel.CancelEventArgs) Handles Schedule1.CurrentLayoutChanging
'To persist user changes in the current layout,
'call the Update method explicitly before changing the layout
If Not Schedule1.CurrentLayout Is Nothing Then
Schedule1.CurrentLayout.Update()
End If
End Sub
In C#:
private void schedule1_CurrentLayoutChanging(object sender, System.ComponentModel.CancelEventArgs e)
{
//To persist user changes in the current layout,
//call the Update method explicitly before changing the layout
if (schedule1.CurrentLayout != null)
{
schedule1.CurrentLayout.Update();
}
}
4) In the Closing event of the form, save the layout file again to be able to preserve the changes the user did (like view, format settings, dates, etc).
In VB:
Private Sub Form1_FormClosing(ByVal sender As System.Object, ByVal e As System.Windows.Forms.FormClosingEventArgs) Handles MyBase.FormClosing
Dim Result As DialogResult
Dim LayoutDir As String
Dim LayoutStream As FileStream
Result = MessageBox.Show("Do you want to preserve the changes in the Schedule control layout?", "Preserve changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question)
If Result = Windows.Forms.DialogResult.Cancel Then
e.Cancel = True
ElseIf Result = Windows.Forms.DialogResult.Yes Then
LayoutDir = "C:\ScheduleLayout.xml"
LayoutStream = New FileStream(LayoutDir, FileMode.Open)
Schedule1.SaveLayoutFile(LayoutStream)
LayoutStream.Close()
End If
End Sub
In C#:
private void Form1_FormClosing(object sender, FormClosingEventArgs e)
{
DialogResult result;
string layoutDir;
FileStream layoutStream;
result = MessageBox.Show("Do you want to preserve the changes in the Schedule control layout?", "Preserve changes", MessageBoxButtons.YesNoCancel, MessageBoxIcon.Question);
if (result == DialogResult.Cancel)
{
e.Cancel = true;
}
else if (result == DialogResult.Yes)
{
layoutDir = + @"C:\ScheduleLayout.xml";
layoutStream = new FileStream(layoutDir, FileMode.Open);
schedule1.SaveLayoutFile(layoutStream);
layoutStream.Close();
}
}
5) Run the project.
Source Of Information : Janus v3.5 Help Files for VS 2008
Subscribe to:
Post Comments (Atom)
0 comments: