Want to win a PS4? Go Premium and enter to win our High-Tech Treats giveaway. Enter to Win

x
?
Solved

lightweight readonly datasource for combo/grid

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

[Webinar] Lessons on Recovering from Petya

Skyport is working hard to help customers recover from recent attacks, like the Petya worm. This work has brought to light some important lessons. New malware attacks like this can take down your entire environment. Learn from others mistakes on how to prevent Petya like worms.

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…
Performance in games development is paramount: every microsecond counts to be able to do everything in less than 33ms (aiming at 16ms). C# foreach statement is one of the worst performance killers, and here I explain why.
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…
Is your data getting by on basic protection measures? In today’s climate of debilitating malware and ransomware—like WannaCry—that may not be enough. You need to establish more than basics, like a recovery plan that protects both data and endpoints.…
Suggested Courses

636 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