Solved

lightweight readonly datasource for combo/grid

Posted on 2006-06-09
6
487 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
[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
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

[Webinar] How Hackers Steal Your Credentials

Do You Know How Hackers Steal Your Credentials? Join us and Skyport Systems to learn how hackers steal your credentials and why Active Directory must be secure to stop them. Thursday, July 13, 2017 10:00 A.M. PDT

Question has a verified solution.

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

Introduction This article series is supposed to shed some light on the use of IDisposable and objects that inherit from it. In essence, a more apt title for this article would be: using (IDisposable) {}. I’m just not sure how many people would ge…
Summary: Persistence is the capability of an application to store the state of objects and recover it when necessary. This article compares the two common types of serialization in aspects of data access, readability, and runtime cost. A ready-to…
If you're a developer or IT admin, you’re probably tasked with managing multiple websites, servers, applications, and levels of security on a daily basis. While this can be extremely time consuming, it can also be frustrating when systems aren't wor…
In this video we outline the Physical Segments view of NetCrunch network monitor. By following this brief how-to video, you will be able to learn how NetCrunch visualizes your network, how granular is the information collected, as well as where to f…

717 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