C# Tri State TreeView Serialization

EDN Admin

Well-known member
Joined
Aug 7, 2010
Messages
12,794
Location
In the Machine
I have im my design a Tri State TreeView for which I create a xml file to serialize. I create my xsd schmea and then i have generated my class for that schema (workflow.xml -> workflow.xsd -> workflow.cs)

I want to parse in xml values "1" or "0" if a box from Tri State is checked or not

My code looks like that:

( WorkflowModulSplitAnalizaSplit() and WorkflowModulCapturaPrelucrareCaptura() are classes generated in workflow.cs )
private void WriteXMLFileUsingValuesFromNodes(string filenamexml)
{
WorkflowModulSplitAnalizaSplit mc_s = new WorkflowModulSplitAnalizaSplit();
if (triStateTreeView1.GetChecked(triStateTreeView1.Nodes[0].Nodes[0].Nodes[0].Nodes[0]) == TriStateTreeView.CheckState.Checked)
{
mc_s.M0_RevertSnapshot = byte.Parse("1");
}
else
{
mc_s.M0_RevertSnapshot = byte.Parse("0");
}
if (triStateTreeView1.GetChecked(triStateTreeView1.Nodes[0].Nodes[0].Nodes[0].Nodes[1]) == TriStateTreeView.CheckState.Checked)
{
mc_s.M0_PowerOnVM = byte.Parse("1");
}
else
{
mc_s.M0_PowerOnVM = byte.Parse("0");
}


XmlSerializer xs_s = new XmlSerializer(typeof(WorkflowModulCapturaPrelucrareCaptura));
FileStream fs_s = new FileStream(@"C:UsersSmartAdmDocumentsvisual studio 2012ProjectsWorkflow_RoboWorkflow_Roboworkflow.xml", FileMode.Create);
xs_s.Serialize(fs_s, mc_s);
fs_s.Close();
//=============================================================================================

WorkflowModulCapturaPrelucrareCaptura mc = new WorkflowModulCapturaPrelucrareCaptura();
if (triStateTreeView1.GetChecked(triStateTreeView1.Nodes[0].Nodes[1].Nodes[1].Nodes[12]) == TriStateTreeView.CheckState.Checked)
{
mc.M3_CopyResultonserver = byte.Parse("1");
}
else
{
mc.M3_CopyResultonserver = byte.Parse("0");
}

if (triStateTreeView1.GetChecked(triStateTreeView1.Nodes[0].Nodes[1].Nodes[1].Nodes[0]) == TriStateTreeView.CheckState.Checked)
{
mc.M3_RevertSnapshot = byte.Parse("1");
}
else
{
mc.M3_RevertSnapshot = byte.Parse("0");
}

XmlSerializer xs = new XmlSerializer(typeof(WorkflowModulCapturaPrelucrareCaptura));
FileStream fs = new FileStream(@"C:UsersSmartAdmDesktopWorkflow_RoboWorkflow_Roboworkflow.xml", FileMode.Create);
xs.Serialize(fs, mc);
fs.Close();
}

private void button1_Click(object sender, EventArgs e)
{
saveFileDialog1.ShowDialog();
this.Refresh();
}

private void saveFileDialog1_FileOk(object sender, CancelEventArgs e)
{
string name = saveFileDialog1.FileName;
WriteXMLFileUsingValuesFromNodes(name);
}


It only writes one node from xml and I lose the other nodes. It is a way in which I can adapt my code so it will write in all nodes from xml.

Thank you very much!

View the full article
 
Back
Top