Solved

lightweight readonly datasource for combo/grid

Posted on 2006-06-09
6
466 Views
Last Modified: 2010-04-16
Hi!

We're looking for the most lightweight solution (memory/speed) for the implementation of a readonly datasource that can be used as a source for single/multi column comboboxes and grids.

Currently we are looking at  deriving from collectionbase thats stores objects made up of a few strings that are accessible using properties, which hence makes them useable as valuemember/displaymember.

2 questions about this:
-is this the best solution we can go at considering our needs? Can we go further so that boxing/unboxing is avoided(other collections?)
-Right now we work with objects that have a property for each member, but if we get the data from a database we do not know the number of columns so: how do we make an object that will dynamically have a property for each column that is stored?

500 points are awarded to whoever provides a helpful answer and some example code.

greetings

Secuteamers
0
Comment
Question by:secuteamers
  • 2
6 Comments
 
LVL 14

Accepted Solution

by:
existenz2 earned 500 total points
ID: 16869199
The most lightweight option i think is using an array of structs, possible enhanced with some extra functionality (if needed).

-Right now we work with objects that have a property for each member, but if we get the data from a database we do not know the number of columns so: how do we make an object that will dynamically have a property for each column that is stored?

That is a very tricky one. You have a few options:
Option 1:
Use Reflection to create classes with the approriate methods. Pro: 1 property foreach column, Cons: Very slow and not very lightweight.

Option 2:
Create a class which implements a enumerator and which loops through all columns, sorta like:
public class ExampleData : IEnumerator
      {
            DataRow dataRow = null;
            DataColumn dc = new DataColumn();
            int index = 0;

            public ExampleData(DataRow row)
            {
                  dataRow = row;
            }

            public bool MoveNext()
            {
                  bool next = false;
                  index++;
                  if(index <= (dataRow.ItemArray.Length-1))
                        next = true;
                  return next;
            }

            public void Reset()
            {
                  index = 0;
            }

            public object Current
            {
                  get { return dataRow[index]; }
            }

            public object[] All
            {
                  get
                  {
                        object[] data = new object[dataRow.ItemArray.Length];
                        for(int i = 0; i < dataRow.ItemArray.Length; i++)
                        {
                              data[i] = dataRow[i];
                        }
                        return data;
                  }
            }
      }
0
 

Author Comment

by:secuteamers
ID: 16869423
been doing some further research, looking into Ilistsource interface, which should do the trick as far as i have read? Continuing...
0
 
LVL 14

Expert Comment

by:existenz2
ID: 16869478
Yes, implementing IListSource would be a tider solution then my second option, with the same result.
0

Featured Post

Live: Real-Time Solutions, Start Here

Receive instant 1:1 support from technology experts, using our real-time conversation and whiteboard interface. Your first 5 minutes are always free.

Question has a verified solution.

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

Extention Methods in C# 3.0 by Ivo Stoykov C# 3.0 offers extension methods. They allow extending existing classes without changing the class's source code or relying on inheritance. These are static methods invoked as instance method. This…
Introduction Hi all and welcome to my first article on Experts Exchange. A while ago, someone asked me if i could do some tutorials on object oriented programming. I decided to do them on C#. Now you may ask me, why's that? Well, one of the re…
Established in 1997, Technology Architects has become one of the most reputable technology solutions companies in the country. TA have been providing businesses with cost effective state-of-the-art solutions and unparalleled service that is designed…
Finds all prime numbers in a range requested and places them in a public primes() array. I've demostrated a template size of 30 (2 * 3 * 5) but larger templates can be built such 210  (2 * 3 * 5 * 7) or 2310  (2 * 3 * 5 * 7 * 11). The larger templa…

776 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