Solved

lightweight readonly datasource for combo/grid

Posted on 2006-06-09
6
455 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
Comment Utility
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
Comment Utility
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
Comment Utility
Yes, implementing IListSource would be a tider solution then my second option, with the same result.
0

Featured Post

Top 6 Sources for Identifying Threat Actor TTPs

Understanding your enemy is essential. These six sources will help you identify the most popular threat actor tactics, techniques, and procedures (TTPs).

Join & Write a Comment

Article by: Ivo
C# And Nullable Types Since 2.0 C# has Nullable(T) Generic Structure. The idea behind is to allow value type objects to have null values just like reference types have. This concerns scenarios where not all data sources have values (like a databa…
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…
Internet Business Fax to Email Made Easy - With eFax Corporate (http://www.enterprise.efax.com), you'll receive a dedicated online fax number, which is used the same way as a typical analog fax number. You'll receive secure faxes in your email, fr…
This video explains how to create simple products associated to Magento configurable product and offers fast way of their generation with Store Manager for Magento tool.

728 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

Need Help in Real-Time?

Connect with top rated Experts

10 Experts available now in Live!

Get 1:1 Help Now