473,387 Members | 1,721 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,387 software developers and data experts.

Help displaying data on datagrid

Iv got a StatisticsContainer object that contains an arraylist of
objects of different types, all inherited from class Statistic. The
statistics class has 2 string public properties, name and stringValue.
The classes that inherit from it use those two properties, plus several
properties of their own of types double and vector. I need to display
this StatisticsContainer class on a datagrid, but I'm having problems
because each of the classes have some different properties. The
datagrid automatically binds to all public properties of the first
entry, but most of these (all but stringValue), are actually unique to
the first entry. What results if i add another entry to the arraylist
is an exception from the reflection namespace. I need to do one of
three things:
1. force the datagrid to display only the properties common to the
statistic base class.
or
2. have the datagrid display little plus marks allowing me to expand
each entry and see all of this unique properties.

or

3. (the best) do both.

The datagrid control is completely confusing me with its myriad
collections of styles. I have no reference books (beyond what i can
find on the web), so I would greatly appreciate some help.

Nov 17 '05 #1
1 1486
Hi,
[Inline]

"Michael Gorbach" <mg******@gmail.com> wrote in message
news:11*********************@g43g2000cwa.googlegro ups.com...
Iv got a StatisticsContainer object that contains an arraylist of
objects of different types, all inherited from class Statistic. The
statistics class has 2 string public properties, name and stringValue.
The classes that inherit from it use those two properties, plus several
properties of their own of types double and vector. I need to display
this StatisticsContainer class on a datagrid, but I'm having problems
because each of the classes have some different properties. The
datagrid automatically binds to all public properties of the first
entry, but most of these (all but stringValue), are actually unique to
the first entry. What results if i add another entry to the arraylist
is an exception from the reflection namespace. I need to do one of
three things:
1. force the datagrid to display only the properties common to the
statistic base class.
This is possible by implementing your own custom collection which implements
ITypedList :

using System.Reflection;
using System.ComponentModel;
using System.Collections;

public class StatisticsContainer : CollectionBase, ITypedList
{
public int Add( Statistic a )
{
return List.Add( a );
}

public Statistic this[int i]
{
get { return (Statistic)List[i]; }
}

// .......
// implement other collection properties the same way ( using List )
// .......

// implementation of ITypedList
public PropertyDescriptorCollection GetItemProperties(PropertyDescriptor[]
listAccessors)
{
if ( listAccessors == null || listAccessors.Length == 0 )
{
PropertyDescriptorCollection pdc = new
PropertyDescriptorCollection(null);

// Using reflection to keep the order of fields
// typeof( Base-Class-Name )
foreach( PropertyInfo pi in typeof(Statistic).GetProperties() )
{
// by default properties are included,
// unless they have the [BindableAttribute(false)].
object[] o = pi.GetCustomAttributes(typeof(BindableAttribute),
false );
if ( o.Length == 0 || ((BindableAttribute)o[0]).Bindable )
{
pdc.Add( TypeDescriptor.CreateProperty( typeof(Statistic),
pi.Name, pi.PropertyType ) );
}
}
return pdc;
}
else
{
// only required for hierarchical collections, not implemented,
// ask if you need help with this
return null;
}
}

// implementation of ITypedList
public string GetListName(PropertyDescriptor[] listAccessors)
{
if ( listAccessors == null || listAccessors.Length == 0 )
{
return this.GetType().Name;
}
else
{
// only required for hierarchical collections, not implemented,
// ask if you need help with this
return null;
}
}

}//end-class
HTH,
Greetings

or
2. have the datagrid display little plus marks allowing me to expand
each entry and see all of this unique properties.

or

3. (the best) do both.

The datagrid control is completely confusing me with its myriad
collections of styles. I have no reference books (beyond what i can
find on the web), so I would greatly appreciate some help.

Nov 17 '05 #2

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

2
by: Shane | last post by:
I made a Database in MS Access, and i want to try to port it over to VB.NET. One thing i have is a subform that is a datasheet. what I want to know, is there away to make the data grid to have...
12
by: Charles Astwood | last post by:
Hi, just starting out working my way round C Sharp and aspx. Used to write all my sites in asp and just need a few pointers in how to display data. I have made a connection to my SQL2000...
2
by: VM | last post by:
When I display data to a Windows datagrid I usually fill the underlying table (in another class) and then, once it contains all the data, I attach it to the grid. But there are some processes that...
4
by: MikeY | last post by:
Hi everyone, In C#, is there a easy way of display files (ie. mp3 files) to a datagrid? If someone can provide me with some code, or advice I would appreciated it. Thanks in advance. MikeY
3
by: vinayak | last post by:
Hi I am displaying data in Datagrid in ASP.NET with Edit/Update functionality for each row. On the same page I have 2 Button controls which submits the request to server. These button controls...
2
by: Ray | last post by:
ASP.NET Newbie ? I have a populated datagrid on my .aspx page, I want to open a second window without all the extra fluff (nav bar, menus, etc) and display a printer friendly version of my...
4
by: Pacific Design Studios | last post by:
I have a DataGrid on Form1 that displays a small amount of information about employees. On Form2 I want to have all the data displaying in text boxes about the employee selected in the datagrid on...
7
by: Aaron | last post by:
Complete code follows. I am new to .NET programming (and programming in general) and I am having a difficult time understanding how to fill a variable in one sub, and then access it from...
1
by: Death | last post by:
Hi all I am having some trouble on displaying datagrid data from my database as i am a beginner for this The error is when calling the DBCommand . It show incorrect syntax near User. But User...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
0
by: ryjfgjl | last post by:
If we have dozens or hundreds of excel to import into the database, if we use the excel import function provided by database editors such as navicat, it will be extremely tedious and time-consuming...
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers,...
0
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.