Note that there are some explanatory texts on larger screens.

plurals
  1. PO
    text
    copied!<p>I would suggest you have a look at <a href="http://tech.pro/tutorial/798/csharp-tutorial-xml-serialization" rel="nofollow">xml serializer</a>. Datatables are a pain to work with, so you could create a "To-Do" class and display the properties of this class after clicking on the corresponding identifier (lets say name) in your combobox. </p> <p>The serialization might not be the problem here, it most likely got more to do with what you try to display in your combobox, and how that is linked to the rows of your datasets...</p> <p><strong>Edit:</strong> I have two possible solutions. They are both buggy and ugly, but its the best one can do within the limits of your implementation. Number one:</p> <p>Make your dataset accessible by all methods in your class:</p> <pre><code>public partial class Form1 : Form { private DataSet dataset; private DataTable datatable; public Form1() { </code></pre> <p>You can then (after initializing it, and making sure its got a table in it, all minor adjustments to your class) do the following in your combobox Eventhandler:</p> <pre><code>private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex &gt; -1) { DataTable tempTable = dataset.Tables[0]; foreach (DataRow row in tempTable.Rows) { if (row[0].ToString() == comboBox1.SelectedItem.ToString()) { label1.Text = row[1].ToString(); label2.Text = row[2].ToString(); label3.Text = row[3].ToString(); label4.Text = row[4].ToString(); label5.Text = row[5].ToString(); label6.Text = row[6].ToString(); } } } } </code></pre> <p>I filled labels with the text, but im pretty sure you can figure out how to fill some other controls as well ;) The second solution is even messier, but it requires no adjustments to your existing code:</p> <pre><code>private void comboBox1_SelectedIndexChanged(object sender, EventArgs e) { if (comboBox1.SelectedIndex &gt; -1) { XmlTextReader xmlreader = new XmlTextReader(@"C:\save.xml"); XmlNodeType nodetype; bool xmlReaderArmed = false; while (xmlreader.Read()) { nodetype = xmlreader.NodeType; if (nodetype == XmlNodeType.Element) { if (xmlreader.Name == "Name") { xmlreader.Read(); if (xmlreader.Value == comboBox1.SelectedItem.ToString()) { label1.Text = xmlreader.Value; xmlReaderArmed = true; } } else if (xmlreader.Name == "Priority" &amp;&amp; xmlReaderArmed) { xmlreader.Read(); label2.Text = xmlreader.Value; } else if (xmlreader.Name == "StartDate" &amp;&amp; xmlReaderArmed) { xmlreader.Read(); label3.Text = xmlreader.Value; } else if (xmlreader.Name == "EndDateSoll" &amp;&amp; xmlReaderArmed) { xmlreader.Read(); label4.Text = xmlreader.Value; } else if (xmlreader.Name == "EndDateIst" &amp;&amp; xmlReaderArmed) { xmlreader.Read(); label5.Text = xmlreader.Value; } else if (xmlreader.Name == "Comment" &amp;&amp; xmlReaderArmed) { xmlreader.Read(); label6.Text = xmlreader.Value; xmlReaderArmed = false; } } } xmlreader.Close(); } </code></pre> <p>I STILL strongly suggest you rework your solution. The entire thing is very unstable, and very hard to maintain. Read up some tutorials about object orientated programming and have a look at some other peoples solutions similar to yours, such as an address book implementation maybe :) Good luck on your endeavours! </p>
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload