?
Solved

lightweight readonly datasource for combo/grid

Posted on 2006-06-09
6
Medium Priority
?
495 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 2000 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

On Demand Webinar: Networking for the Cloud Era

Did you know SD-WANs can improve network connectivity? Check out this webinar to learn how an SD-WAN simplified, one-click tool can help you migrate and manage data in the cloud.

Question has a verified solution.

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

In order to hide the "ugly" records selectors (triangles) in the rowheaders, here are some suggestions. Microsoft doesn't have a direct method/property to do it. You can only hide the rowheader column. First solution, the easy way The first sol…
We all know that functional code is the leg that any good program stands on when it comes right down to it, however, if your program lacks a good user interface your product may not have the appeal needed to keep your customers happy. This issue can…
If you’ve ever visited a web page and noticed a cool font that you really liked the look of, but couldn’t figure out which font it was so that you could use it for your own work, then this video is for you! In this Micro Tutorial, you'll learn yo…
Have you created a query with information for a calendar? ... and then, abra-cadabra, the calendar is done?! I am going to show you how to make that happen. Visualize your data!  ... really see it To use the code to create a calendar from a q…
Suggested Courses
Course of the Month11 days, 7 hours left to enroll

752 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