PC Review


Reply
Thread Tools Rate Thread

DataGrid Binding to Complex Custom Collection

 
 
Conawapa11
Guest
Posts: n/a
 
      14th Nov 2003
I'm having trouble figuring this problem out and every example out
there deals with simple objects within a custom collection. Take this
example:

public class ComplexClass
{
private int id;
private InnerClass anotherOne;

public int ID
{
get { return id; }
}
public InnerClass AnotherOne
{
get { return anotherOne; }
}
}

public class InnerClass
{
private int id;
private string name;

public int ID
{
get { return id; }
}
public string Name
{
get { return name; }
}
}

then I have a
public class ComplexCustomCollection : CollectionBase
that contains a list of ComplexClass objects.

Now in my Custom Control, I have a DataGrid that I want to bind to
this ComplexCustomCollection.

When creating columns, I have something like:

BoundColumn column = new BoundColumn();
column.DataField = "ID";
column.HeaderText = "ID #";
myGrid.Columns.Add(column);

column = new BoundColumn();
column.DataField = "AnotherOne.Name"; // just a guess
column.HeaderText = "Another Name";
myGrid.Columns.Add(column);

myGrid.DataSource = myComplexCustomCollection;
myGrid.DataBind();


Which, when ran results in:
A field or property with the name 'AnotherOne.Name' was not found on
the selected datasource.
How can I bind to that inner class's properties?


Any help would be much appreciated. Thanks in advance...
 
Reply With Quote
 
 
 
 
Michael Tkachev
Guest
Posts: n/a
 
      14th Nov 2003
Hi,

DataGrid trys to find Property "AnotherOne.Name". But your class
"ComplexClass" has propery "AnotherOne"!
You have to create Property "AnotherOne_Name"

public class ComplexClass
{
...
public string AnotherOne_Name
{
return anotherOne.Name;
}
...
}

Then for each item of the myComplexCustomCollection you will be able to find
Property "AnotherOne_Name".
This Property will show to you name of the class "AnotherOne".
Try to do it.

bye

The Best Regards,
Web Developer
Michael Tkachev


"Conawapa11" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> I'm having trouble figuring this problem out and every example out
> there deals with simple objects within a custom collection. Take this
> example:
>
> public class ComplexClass
> {
> private int id;
> private InnerClass anotherOne;
>
> public int ID
> {
> get { return id; }
> }
> public InnerClass AnotherOne
> {
> get { return anotherOne; }
> }
> }
>
> public class InnerClass
> {
> private int id;
> private string name;
>
> public int ID
> {
> get { return id; }
> }
> public string Name
> {
> get { return name; }
> }
> }
>
> then I have a
> public class ComplexCustomCollection : CollectionBase
> that contains a list of ComplexClass objects.
>
> Now in my Custom Control, I have a DataGrid that I want to bind to
> this ComplexCustomCollection.
>
> When creating columns, I have something like:
>
> BoundColumn column = new BoundColumn();
> column.DataField = "ID";
> column.HeaderText = "ID #";
> myGrid.Columns.Add(column);
>
> column = new BoundColumn();
> column.DataField = "AnotherOne.Name"; // just a guess
> column.HeaderText = "Another Name";
> myGrid.Columns.Add(column);
>
> myGrid.DataSource = myComplexCustomCollection;
> myGrid.DataBind();
>
>
> Which, when ran results in:
> A field or property with the name 'AnotherOne.Name' was not found on
> the selected datasource.
> How can I bind to that inner class's properties?
>
>
> Any help would be much appreciated. Thanks in advance...



 
Reply With Quote
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
trouble binding a datagrid to a custom collection =?Utf-8?B?dmlrdG9yOTk5MA==?= Microsoft ASP .NET 1 16th Mar 2006 09:56 PM
method or operation is not implemented error when binding a datagrid to a custom collection. Beth Microsoft Dot NET Compact Framework 0 19th Sep 2005 08:19 PM
binding a datagrid to a custom collection object? Beth Microsoft Dot NET Compact Framework 0 19th Sep 2005 07:36 PM
Datagrid: Binding to custom collection Carlos Campos Microsoft Dot NET Framework Forms 3 24th Jun 2004 05:09 PM
Binding a Datagrid to a Custom Collection Stephajn Craig Microsoft VB .NET 0 4th Feb 2004 06:54 PM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 08:56 AM.