Creating userform based on nodes in XML

  • Thread starter Thread starter kocsism
  • Start date Start date
K

kocsism

Guest
I have dinamicaly generated buttons on one of my userforms. The buttons are being generated based on nodes in an xml file.



namespace e2e_template
{
public partial class Form3 : Form
{
public Form3(string data)
{
string Username = System.Security.Principal.WindowsIdentity.GetCurrent().Name.ToString();

string Result = Username.Length <= 4 ? "" : Username.Substring(4);


string Path = $"C:\\Users\\{Result}\\Documents\\template\\config.xml";
//MessageBox.Show(Path);

XmlDocument doc = new XmlDocument();
doc.Load(Path);
XmlNodeList templates = doc.SelectNodes("//template");


int x = 10;
int y = 10;


foreach (XmlNode template in templates)
{
string name = template.SelectSingleNode("name").InnerText.Trim();
Button button = new Button
{
Text = name,
Width = 250,
Height = 75,
Left = x + 20,
Top = y,
};
button.Click += new EventHandler(Button_Click);
Controls.Add(button);
y += button.Height + 5;
}
InitializeComponent();

}
private void Button_Click(object sender, EventArgs e)
{
Form4 form = new Form4();
form.ShowDialog();
}
}

}


I would like that when I click on a button and is opening a new userform (form4 in this case) I would like to show text between other nodes.

<template id="Some Template ID">

<name>Template name</name>
<description>Discription of this template</description>
<item id="1">1st item of this template</item>
<item id="2">2nd item of this template</item>
<item id="3">3rd item of this template</item>
<item id="4">4th item of this template</item>

</template>


So if I click on the button with caption for example "Template name" it will open user form4 as it does now, but I would see the item ID listed 1 under another. but the tricky part is that the number of IDs are different. I mean there can be 4 but also 10. how should I approach this problem?

Continue reading...
 

Similar threads

K
Replies
0
Views
66
kocsism
K
B
Replies
0
Views
104
Born2Achieve
B
N
Replies
0
Views
61
nothingisimpossible
N
H
Replies
0
Views
423
Here4FreeHelp
H
Back
Top