Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

Adding some inputs into a <List>

Posted on 2009-03-31
3
Medium Priority
?
148 Views
Last Modified: 2012-05-06
I can manage to get this to work with the top class but when I have lower classes I dont get this to work.

I want a list to be printet out in a listbox. Like this:

Die hard    Date     Distributor      Category

but all the code includes is the thing from class movie and not audioVideo
this wont come out
        private string m_country;
        private string m_language;
        private decimal  m_price;
        private DateTime m_releaseDate;
        private int m_runtime;
        private string m_title;

this willl

        private string m_category;        
        private string m_system;
        private string m_distributor;

See code


List<AudioVideo> audioVideoLista = new List<AudioVideo>();
List<Movie> movieVideoLista = new List<Movie>();
------------------------------------------------------
  //*******************************************************************
        //          ReadXmlFileFilm
        //*******************************************************************
        private void ReadXmlFileFilm()
        {
            string xmlFile;
            xmlFile = Environment.CurrentDirectory;
            xmlFile = xmlFile.Substring(0, xmlFile.Length - 9);
            xmlFile = xmlFile + "xml\\videofilm.xml";
 
            XmlTextReader reader = new XmlTextReader(xmlFile);
            XmlDocument doc = new XmlDocument();
            doc.Load(xmlFile);
 
            // Loop through all the videofilmer/videofilm elements
            foreach (XmlNode film in doc.DocumentElement.SelectNodes("videofilm"))
            {
                Movie mv = new Movie();
 
                XmlNode tempNode;
                // titel
                tempNode = film.SelectSingleNode("titel");
                string title = (tempNode == null ? "" : tempNode.InnerText);
                // språk
                tempNode = film.SelectSingleNode("språk");
                string sprak = (tempNode == null ? "" : tempNode.InnerText);
                // datum
                tempNode = film.SelectSingleNode("datum");
                DateTime datum = DateTime.MinValue;
                if (tempNode != null) datum = DateTime.Parse(tempNode.InnerText);
                // pris
                tempNode = film.SelectSingleNode("pris");
                decimal pris = -1;
                if (tempNode != null) pris = decimal.Parse(tempNode.InnerText);
                // tid
                tempNode = film.SelectSingleNode("tid");
                int tid = -1;
                if (tempNode != null) tid = Int32.Parse(tempNode.InnerText);
                // land
                tempNode = film.SelectSingleNode("land");
                string land = (tempNode == null ? "" : tempNode.InnerText);
                //Category
                tempNode = film.SelectSingleNode("category");
                string category = (tempNode == null ? "" : tempNode.InnerText);
                //System
                tempNode = film.SelectSingleNode("system");
                string system = (tempNode == null ? "" : tempNode.InnerText);
                //distributor
                tempNode = film.SelectSingleNode("distributor");
                string distributor = (tempNode == null ? "" : tempNode.InnerText);
                
                mv.Price = pris;
                mv.RunTime = tid;
                mv.Language = sprak;
                mv.Title = title;
                mv.Date = datum;
                mv.Country = land;
                mv.Category = category;
                mv.Distributor = distributor;
                mv.System = system;
                movieVideoLista.Add(mv);
            }
 
------------------------------------
 
 
namespace AudioVideoGallery.AudioVideoFiles
{
    class AudioVideo
    {
 
        #region Deklaration
 
        private string m_country;
        private string m_language;
        private decimal  m_price;
        private DateTime m_releaseDate;
        private int m_runtime;
        private string m_title;
 
        #endregion
 
        #region Egenskaper
 
 
        //*******************************************************************
        //          Contries
        //*******************************************************************
        public string Country
        {
            get { return m_country; }
            set { m_country = value; }
        } //end Contries
 
 
 
        //*******************************************************************
        //          Language
        //*******************************************************************
        public string Language
        {
            get { return m_language; }
            set { m_language = value; }
        } //end Language
 
 
        //*******************************************************************
        //          Price
        //*******************************************************************
        public decimal Price
        {
            get { return m_price; }
            set { m_price = value; }
        } //end Price
 
 
        //*******************************************************************
        //          Date
        //*******************************************************************
        public DateTime Date
        {
            get { return m_releaseDate; }
            set { m_releaseDate = value; }
        } //end Date
 
 
        //*******************************************************************
        //          RunTime
        //*******************************************************************
        public int RunTime
        {
            get { return m_runtime; }
            set { m_runtime = value; }
        } //end RunTime
 
 
        //*******************************************************************
        //          Title
        //*******************************************************************
        public string Title
        {
            get { return m_title; }
            set { m_title = value; }
        } //end Title
 
 
        #endregion
 
 
 
        #region Metoder
 
 
        //*******************************************************************
        //          ToString
        //*******************************************************************
        public override string ToString()
        {
            return "" + m_title + "_!_" + m_language + "_!_" + m_releaseDate + "_!_" +m_price +"_!_" + m_runtime + "_!_" + m_country + "_!_";
        } //end ToString
 
        #endregion
 
    }
}
 
---------------------------------------------
 
 
namespace AudioVideoGallery.AudioVideoFiles
{
    class Movie : AudioVideo
    {
        #region Deklaration
 
        private string m_category;        
        private string m_system;
        private string m_distributor;
 
        #endregion
 
        
        
        #region Egenskaper
 
 
        //*******************************************************************
        //          Category
        //*******************************************************************
        public string Category
        {
            get { return m_category; }
            set { m_category = value; }
        } //end Category
 
 
 
        //*******************************************************************
        //          System
        //*******************************************************************
        public string System
        {
            get { return m_system; }
            set { m_system = value; }
        } //end System
 
         
 
        
        //*******************************************************************
        //          Distributor
        //*******************************************************************
        public string Distributor
        {
            get { return m_distributor; }
            set { m_distributor = value; }
        } //end Distributor
 
 
        #endregion
 
 
 
        #region Metoder
 
 
        //*******************************************************************
        //          ToString
        //*******************************************************************
        public override string ToString()
        {
            return "" + m_category + "_!_" + m_distributor + "_!_" + m_system + "_!_";
        } //end ToString
 
        #endregion
    }
}

Open in new window

0
Comment
Question by:Mickeys
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 2
3 Comments
 
LVL 15

Accepted Solution

by:
oobayly earned 2000 total points
ID: 24028120
If I understand your meaning, when you use List<Movie> movieVideoLista as the datasource for the listbox, the text displayed in the listbox isn't what you expect.

I think you wanted to be able to access m_title, m_releaseDate in the class Movie, but these are marked as private in AudioVideo, so they can't be accessed. You could always declare them as protected, but I wouldn't recommend it.

Apologies if this is not what you wanted.
public override string ToString() {
  //return "" + m_category + "_!_" + m_distributor + "_!_" + m_system + "_!_";
  return this.Title + "_!_" + this.Date + "_!_" + this.Distributor + "_!_" +
    this.Category + "_!_";
} //end ToString

Open in new window

0
 

Author Comment

by:Mickeys
ID: 24028193
but I thought they should be private. I use the get and set to access them.

The code you wrote is that in the top class AudioVideo
or the lower Movie.
0
 
LVL 15

Expert Comment

by:oobayly
ID: 24028239
The code I wrote would replace public override string ToString() in Movie.
You're absolutely correct, I would have done the same and made m_title private. The only reason I suggested using Protected is because I thought you may have been trying to access m_title from Movie.ToString()
0

Featured Post

Free Tool: Path Explorer

An intuitive utility to help find the CSS path to UI elements on a webpage. These paths are used frequently in a variety of front-end development and QA automation tasks.

One of a set of tools we're offering as a way of saying thank you for being a part of the community.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Article by: Najam
Having new technologies does not mean they will completely replace old components.  Recently I had to create WCF that will be called by VB6 component.  Here I will describe what steps one should follow while doing so, please feel free to post any qu…
This article describes a simple method to resize a control at runtime.  It includes ready-to-use source code and a complete sample demonstration application.  We'll also talk about C# Extension Methods. Introduction In one of my applications…
Video by: ITPro.TV
In this episode Don builds upon the troubleshooting techniques by demonstrating how to properly monitor a vSphere deployment to detect problems before they occur. He begins the show using tools found within the vSphere suite as ends the show demonst…
Are you ready to place your question in front of subject-matter experts for more timely responses? With the release of Priority Question, Premium Members, Team Accounts and Qualified Experts can now identify the emergent level of their issue, signal…
Suggested Courses

636 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question