473,378 Members | 1,317 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,378 software developers and data experts.

.NET 1.1 DataGrid: Showing public properties with an Interface Type of objects in an IList

Hi,

I have the following problem:
The DataSource of a DataGrid can be set to an IList. The DataGrid
nicely lists the objects in the IList,
showing all the public properties of the objects as the columns of the
datagrid...
The public properties with a primitive type are shown
The public properties with userdefined types are also shown, using the
eventually overridden ToString method.
But...... when the Design-Time type is an interface type, the datagrid
is not showing the ToStrings value of that property, eventhough using
the debugger the runtime type shows an instance of the concrete class.
Does anyone knows the reason of this behaviour and a solution for it?
(e.g. how to make the DataGrid discover the overridden ToString method
of the concrete instance of the Interface Type)

An example (note: the only usage of IMyStructure is with the property
MyListRecord.Structure, the
private member MyListRecord.structure is of type MyStructure (the
class-type, not the interface-type)

public Form1()
{
//
// Required for Windows Form Designer support
//
InitializeComponent();

IList il = new ArrayList();
MyStructure ms1 = new MyStructure();
ms1.X = 10;

MyStructure ms2 = new MyStructure();
ms2.X = 15;

MyListRecord mlr1 = new MyListRecord();
mlr1.Structure = ms1;
mlr1.Name = "Record1";

MyListRecord mlr2 = new MyListRecord();
mlr2.Structure = ms2;
mlr2.Name = "Record2";

il.Add(mlr1);
il.Add(mlr2);

this.dataGrid1.DataSource = il;
}

public class MyListRecord
{
private string name;
private MyStructure structure;

public MyListRecord()
{
//
// TODO: Add constructor logic here
//
}

public string Name
{
get { return name; }
set { name = value; }
}

public IMyStructure Structure
{
get { return structure; }
set { structure = (MyStructure) value; }
}
}
public class MyStructure : IMyStructure
{

int x;

public int X
{
get { return x; }
set { x = value; }
}

public override string ToString()
{
return String.Format("X: {0}", x);
}
}

Thanx in advance ,
Marco

May 30 '07 #1
0 1552

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

Similar topics

2
by: SammyBar | last post by:
Hi, I'm trying to bind a custom collection class to a data grid, following the guidelines from the article http://msdn.microsoft.com/msdnmag/issues/05/08/CollectionsandDataBinding/default.aspx....
5
by: K | last post by:
I created a collection which is derived from ArrayList and implements IBindingList and ITypedList. Then I bound the DataSource of a data grid into the collection. It could show up the data but...
0
by: berg | last post by:
All, I am binding an ArrayList full of custom objects to an DataGrid. The property in the custom class are all public. I define a DataGridTableStyle and set the MappingName to "ArrayList". I...
0
by: Wiktor Zychla | last post by:
Hello, I am thinking of a general solution to the specific issue and I hope someone has some more experience on that. Up to now I use the ListView as the primary control for collections of...
6
by: GingerNinja | last post by:
Hi Everybody, its about my 4th day on C# and all seems to be going smoothly however I've started to get into Datagrids and in particular binding data sources to them. In the documentation it says I...
9
by: Morten | last post by:
Hi! I have a problem displaying some values in a datagrid. I have an array that consists of a number of objects. Each object has 2 properties: Name and a list of web addresses. (e.g: Name:...
2
by: pei_world | last post by:
I want to implement a key hit with enter to dropdown a combobox that is in the datagrid. in this case I need to override its original behaviours. I found some codes from the web. Does anyone know...
4
by: Greg Williams | last post by:
Can anyone tell me please if its possible to bind a datagrid to an array of objects (defined by me) so that when i update the contents of the array, the data grid updates its display. Any tips...
2
by: Prime | last post by:
Hi All ... I'm writing a small shopping cart app (school assignment) and need to list all the books that a user selects. I have created a "BookBasket" object that contains among other things...
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...
0
by: ryjfgjl | last post by:
In our work, we often need to import Excel data into databases (such as MySQL, SQL Server, Oracle) for data analysis and processing. Usually, we use database tools like Navicat or the Excel import...
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: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
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: 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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
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...

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.