Results 1 to 1 of 1

Thread: C# - Event handler can't access parent function objects.

  1. #1
    Join Date
    Oct 2009
    Beans
    Hidden!

    Question C# - Event handler can't access parent function objects.

    As simple as that .. how do I make global objects ? Once you click on the list item, I need it to load appropriate description, but so far, seems impossible.

    Code:
            public void FetchData(string url)
            {
                XmlDocument xDoc = new XmlDocument();
                xDoc.Load(url);
                XmlNodeList title = xDoc.GetElementsByTagName("title");
                XmlNodeList description = xDoc.GetElementsByTagName("description");
    
                for (int i = 0; i < title.Count; i++)
                {
                    lstEntries.Items.Add(title[i].InnerText);
                }
    
                lstEntries.Click += new System.EventHandler(lstEntries_OnClick);
            }
    
            private void lstEntries_OnClick(object sender, System.EventArgs e)
            {
                // description array can't be accessed from here
            }
    Last edited by OpenGuard; October 21st, 2009 at 07:25 PM. Reason: fixed by moving the object outside of the function

Bookmarks

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •