Click here to Skip to main content
15,910,981 members
Home / Discussions / C#
   

C#

 
Questionis it possible to forcE thumbnail view in open dialog? Pin
misterbear5-Aug-04 1:33
misterbear5-Aug-04 1:33 
QuestionWhich richTextBox Event to use ? Pin
evdoxos5-Aug-04 1:16
evdoxos5-Aug-04 1:16 
AnswerRe: Which richTextBox Event to use ? Pin
Heath Stewart5-Aug-04 2:55
protectorHeath Stewart5-Aug-04 2:55 
GeneralRe: Which richTextBox Event to use ? Pin
evdoxos5-Aug-04 3:09
evdoxos5-Aug-04 3:09 
GeneralRe: Which richTextBox Event to use ? Pin
Heath Stewart5-Aug-04 3:14
protectorHeath Stewart5-Aug-04 3:14 
GeneralRe: Which richTextBox Event to use ? Pin
evdoxos5-Aug-04 3:24
evdoxos5-Aug-04 3:24 
QuestionProbably Reflection... but how? Pin
matthias s.5-Aug-04 1:05
matthias s.5-Aug-04 1:05 
AnswerRe: Probably Reflection... but how? Pin
Heath Stewart5-Aug-04 2:47
protectorHeath Stewart5-Aug-04 2:47 
Start by reading Discoverying Type Information at Runtime[^] in the .NET Framework SDK.

If I were you, however, write a little more elegant solution (still using either reflection or the ComponentModel, which is a little easier to use - see the class documentation for the TypeDescriptor for a starting point). Derive all your collections from a single base class (perhaps CollectionBase or some other base class that exposes a common base class for all your objects, which might define common properties - don't use fields - like ID and Name, for example).

Also define an Attribute-derived class for fields you want to be mapped to columns (perhaps with an optional column heading for better control) like so:
[AttributeUsage(AttributeTargets.Property)]
public class ColumnAttribute : Attribute
{
  string heading;
  public ColumnAttribute()
  {
  }
  public ColumnAttribute(string heading)
  {
    this.heading = heading;
  }
  public string Heading
  {
    get { return this.heading; }
  }
}
As you're enumerating properties, only show properties attributed with that attribute in the ListView, optionally using the Heading for the actual heading text (in case the property name to heading name mapping wasn't the same). You could even define some sort of order with the attribute for additional layout capabilities.

This would be attributed on properties of the objects being collected, however. The collection is rather moot (you could have one that just accepts the base class of all the other types, for example).

As far as loading this information, that really depends on what you're loading it from. The collection could be written as a smart class that knows which types to create based on the information presented to it (the navigational tree in our flag ship product works this way). You could go a step further and use a provider pattern to modularize how that information is obtained (having ADO.NET clients to get it from a database, XML Serialization providers, etc.).

XML Serialization may also be a good idea to use. Read XML and SOAP Serialization[^] in the .NET Framework SDK for more information (you can ignore the SOAP information, as that commonly applies to Web Services and .NET Remoting and is just a particular grammar of XML).

There's a lot of things you could do, but it's important you understand the concept of polymorphism: types deriving from other types that can override some information, basically. Implementing a good object model can save you a lot of time and create a more elegant solution that is easier to change, extend, and understand.

 

Microsoft MVP, Visual C#
My Articles
GeneralRe: Probably Reflection... but how? Pin
matthias s.5-Aug-04 3:26
matthias s.5-Aug-04 3:26 
GeneralRe: Probably Reflection... but how? Pin
Heath Stewart5-Aug-04 3:35
protectorHeath Stewart5-Aug-04 3:35 
Generalget opened folder in Outlook Pin
Stephan Wright5-Aug-04 0:36
Stephan Wright5-Aug-04 0:36 
GeneralRe: get opened folder in Outlook Pin
Michael P Butler5-Aug-04 4:09
Michael P Butler5-Aug-04 4:09 
GeneralRe: get opened folder in Outlook Pin
Stephan Wright5-Aug-04 22:46
Stephan Wright5-Aug-04 22:46 
GeneralRe: get opened folder in Outlook Pin
Michael P Butler5-Aug-04 22:51
Michael P Butler5-Aug-04 22:51 
GeneralRe: get opened folder in Outlook Pin
Stephan Wright5-Aug-04 23:01
Stephan Wright5-Aug-04 23:01 
GeneralRe: get opened folder in Outlook Pin
Michael P Butler5-Aug-04 23:17
Michael P Butler5-Aug-04 23:17 
Generaldisable poweroff function Pin
JockerSoft4-Aug-04 22:57
JockerSoft4-Aug-04 22:57 
GeneralRe: disable poweroff function Pin
leppie5-Aug-04 0:45
leppie5-Aug-04 0:45 
GeneralRe: disable poweroff function Pin
Heath Stewart5-Aug-04 1:46
protectorHeath Stewart5-Aug-04 1:46 
GeneralRe: disable poweroff function Pin
Heath Stewart5-Aug-04 2:24
protectorHeath Stewart5-Aug-04 2:24 
GeneralRe: disable poweroff function Pin
Dave Kreskowiak5-Aug-04 8:10
mveDave Kreskowiak5-Aug-04 8:10 
GeneralRe: disable poweroff function Pin
JockerSoft5-Aug-04 22:25
JockerSoft5-Aug-04 22:25 
Questionhow to check if instance is running Pin
Stephan Wright4-Aug-04 22:48
Stephan Wright4-Aug-04 22:48 
AnswerRe: how to check if instance is running Pin
leppie4-Aug-04 22:57
leppie4-Aug-04 22:57 
AnswerRe: how to check if instance is running Pin
exhaulted4-Aug-04 23:09
exhaulted4-Aug-04 23:09 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.