Dean White Dean White - 2 months ago 7
C# Question

Simplest and best way to display a list of items on Windows Form application using C#

At my school I was handed a project for my C# course. It's a fairly simple project but I don't know how to go about doing it or even start doing it. So I'll just get to it then.


I am supposedly a developer hired by a book company that needs a developer to code an application for them to work on one machine in the work place.

Users should be able to do the following with the application:


  • View a list of books, as well as a list of Audio publications

  • Create new records for books and audio



The application should adhere to the following specifications:


  • It must be windows form

  • It must be user friendly and easy to navigate

  • Data should be saved to a file when application closes and be read back into it when it opens

  • It must perform appropriate input validation

  • It must be well designed and support future changes and the business is growing



The following data needs to be stored about the publications:

Book:


  • Publish date

  • Title

  • Author

  • ISBN number

  • Type of book (enum)

  • Type of over (enum)



Audio:


  • Publish date

  • Title

  • Artist

  • Number of tracks

  • total length

  • Type of audio (enum)




I need to make use of object-orientated programming concepts such as classes, properties, methodes, inheritance and polymorphism.

Basically what I need to know is how should I display the information on the form and what is the best way to create new records of that info and what format to save it in.

We haven't learnt anything about grids, so I doubt it's that. We have only learnt how to read/write from text files. Also I suspect that I need to create a class for all the publications and create two child classes for the Book and Audio in order to handle the data that is different between them.

Answer

I encourage you to go on programming with C# :)

This application is more simple than it looks at first sight, you just need to split the requirements in smaller parts and start doing.

I'll show you how I would do it:

1. Create classes of type Book and Audio with the fields you've listed above: this will be useful to store and list the information. You will probably need methods and/or properties to retrieve this information.

2. Use a List<Book> and a List<Audio> to store the publications that will be read from the text files: I'm supposing that you will take the list of Audio and Books from there, that's why you've been taught how to read txt files :) Here you can find how to use List<T> objects.

3. Display the information in a grid: you can create a Grid and add to it columns and rows to display what you've read in the txt file. For doin' that, you will need to loop through the List<T> and retrieving its field values. I let you documentation of the Grid class.

4. Create a form for creating new records: In this form you will need to add controls such as Drop-down lists(for Enum fields for example) or Text-Boxes. You will have to check if all the fields are filled and then write their values in a txt file to store the new records.

You have also to take into account how the design of this application will be. As your teacher has asked for, it has to be user-friendly and easy to navigate.

I let a kind of tutorial to give you something to start from :)

Comments