I'm new to C# so I will try to explain this to the best of my abillity.
I'm creating a simple podcast-application in C# and trying to use an XML-reader to recieve an RSS feed and then putting that information into diffrent winforms.
I've worked out how to get the main information I want into a listBox. What I cannot figure out however, is to get another piece of information (the summary) from the RSS feed into a richTextBox by clicking a list item in the listBox.
The class I made to read the RSS feed.
List item
public class RSSreader { public static List<Tuple<string, string>> rssRead(string url) { string subject = ""; string summary = ""; var x = ""; var y = ""; var count = 0; var list = new List<Tuple<string, string>>(); try { XmlReader reader = XmlReader.Create(url); SyndicationFeed feed = SyndicationFeed.Load(reader); reader.Close(); foreach (SyndicationItem item in feed.Items) { count++; subject = item.Title.Text; summary = item.Summary.Text; x += count + " " + subject + " "; list.Add(new Tuple<string, string>("Avsnitt " + count+ " " + subject, summary)); } } catch (Exception ex) { Console.WriteLine(ex); } //Datahandler.SavePodFeed(list); return list ; } } public class RSSreader { public static List<Tuple<string, string>> rssRead(string url) { string subject = ""; string summary = ""; var x = ""; var y = ""; var count = 0; var list = new List<Tuple<string, string>>(); try { //string urlX = "http://feeds.soundcloud.com/users/soundcloud:users:298230954/sounds.rss"; XmlReader reader = XmlReader.Create(url); SyndicationFeed feed = SyndicationFeed.Load(reader); reader.Close(); foreach (SyndicationItem item in feed.Items) { count++; subject = item.Title.Text; summary = item.Summary.Text; x += count + " " + subject + " "; list.Add(new Tuple<string, string>("Avsnitt " + count+ " " + subject, summary)); } } catch (Exception ex) { Console.WriteLine(ex); } return list ; } } What im using to populate the listbox
private void button1_Click(object sender, EventArgs e) { var list = RSSreader.rssRead(tbxURL.Text); foreach (Tuple<string, string> item in list) { listBox2.Items.Add(item.Item1); } listBox2.Items.Add(RSSreader.rssRead(tbxURL.Text)); } My take on populating the richTextBox from the listBox with the summary onclick.
private void listBox2_MouseClick(object sender, MouseEventArgs e) { var list = RSSreader.rssRead(tbxURL.Text); foreach (Tuple<string, string> item in list) { if (item != listBox2.SelectedItem) { richTextBox1.Text = item.Item2.ToString(); } } } I don't get any errors but it's only populating the richTextBox with the same information no matter which element in the list I click.