Using DataRelation with custom collection and windows datagrid

G

Guest

Hi.

I have a custom collection called TransactionCollection (using
collectionbase). I have created an object called CurrencyTransaction using
this collection and it has two TransactionCollection objects (called
TTTransactions and ChequeTransactions) exposed as properties.

I am binding the CurrencyTransaction to a Windows.Forms DataGrid and it's
working fine. You can expand the rows and view the two nested collections and
navigate between the collections no problem. However, on the grid they are
the names of the properties which doesn't really help the novice use.

I have used the DataRelation object with a dataset to rename nested tables
with nice names such as "View Transactions" but I'm no using a dataset and
I've no desire to use a dataset. Is there any way I can use the DataRelation
object with custom collection i.e. an interface I could implement. Or is
there an attribute I could place on the nested collection properties?

Any help greatly appreciated.

Thanks in advance,
 
F

Frans Bouma [C# MVP]

Tomas said:
Hi.

I have a custom collection called TransactionCollection (using
collectionbase). I have created an object called CurrencyTransaction
using this collection and it has two TransactionCollection objects
(called TTTransactions and ChequeTransactions) exposed as properties.

I am binding the CurrencyTransaction to a Windows.Forms DataGrid and
it's working fine. You can expand the rows and view the two nested
collections and navigate between the collections no problem. However,
on the grid they are the names of the properties which doesn't really
help the novice use.

I have used the DataRelation object with a dataset to rename nested
tables with nice names such as "View Transactions" but I'm no using a
dataset and I've no desire to use a dataset. Is there any way I can
use the DataRelation object with custom collection i.e. an interface
I could implement. Or is there an attribute I could place on the
nested collection properties?

Implement ITypedList on your CurrencyTransaction collection. See for
an example and info how to do that:
http://weblogs.asp.net/fbouma/archive/2004/04/19/115841.aspx

In short: you have to provide property descriptors for the properties
which represent the child collections.

Frans

--
 
G

Guest

Hi Frans

I'm sorry, but I'm a little confused. I've implemented the ITypedList to my
CurrencyCollection and it's showing the four properties of the Currency
contained within this list.

CurrencyName
CurrencyAbbreviation
TTTransactions (collection)
ChequeTransactions (collection)

Am I trying to rename (in the grid) the TTTransactions and ChequeTransaction
properties since these are my nested collections?

I can loop through the PropertyDescriptor objects but all the properties of
them are readonly.

I'm not sure of my next step,

Regards,
 
F

Frans Bouma [C# MVP]

Tomas said:
Hi Frans

I'm sorry, but I'm a little confused. I've implemented the ITypedList
to my CurrencyCollection and it's showing the four properties of the
Currency contained within this list.

CurrencyName
CurrencyAbbreviation
TTTransactions (collection)
ChequeTransactions (collection)

Am I trying to rename (in the grid) the TTTransactions and
ChequeTransaction properties since these are my nested collections?

I can loop through the PropertyDescriptor objects but all the
properties of them are readonly.

I'm not sure of my next step,

You should implement your own PropertyDescriptor class. Simply derive
from PropertyDescriptor and override several methods/properties. For
example, to set a value, use:
component.GetType().GetProperty(this.Name).SetValue(component, value,
null);
in your override of SetValue().

then return the PropertyDescriptorCollection with the properties of
your own type, which WILL have the right names :)

Frans

--
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top