Experts,
I'm attempting to advance my understanding of XML. I have dowloaded an xml document in the following format:
I have a window from with a combobox and four textboxes. When the form initiates it loads the titles (e.g. The Distinguished Gentleman, Her Alibi, and Other People's Money) into the combobox. Now, I'm trying to read the other fields into designated textboxes based on the combobox input. For example, if the user selectes "The Day After Tomorrow" via the combobox, and clicks the button_1 method, the textboxes would then be populated with the following:
Director.Text = Roland Emmerich
Length.Text=124 Minutes
Format .Text = DVD
Rating.Text= PG-13
I would appreciate any example code you could offer to help me figure this out. I would also welcome any recommendations for a good XML tutorial book, as it relates to c#.
Hirendra SisodiyaPosted Mar 8, 2010, 2:02 AM
private DataSet ds;
private void Form1_Load(object sender, EventArgs e)
{
string myXMLfile = "C:\\test.xml";
ds = new DataSet();
try
{
ds.ReadXml(myXMLfile);
for (int i = 0; i <= ds.Tables[0].Rows.Count - 1; i++)
{
comboBox1.Items.Add(ds.Tables[0].Rows[i][0].ToString());
}
comboBox1.SelectedIndex = 0;
}
catch (Exception ex)
{
MessageBox.Show(ex.ToString());
}
}
private void comboBox1_SelectedIndexChanged(object sender, EventArgs e)
{
int i=comboBox1.SelectedIndex;
textBox1.Text=ds.Tables[0].Rows[i][1].ToString();
textBox2.Text = ds.Tables[0].Rows[i][2].ToString();
textBox3.Text = ds.Tables[0].Rows[i][3].ToString();
textBox4.Text = ds.Tables[0].Rows[i][4].ToString();
}
thank you
matthew kingPosted Mar 8, 2010, 10:34 AM
Sam HobbsPosted Mar 8, 2010, 1:14 AM