How do i bind such a class to datagrid?

J

Julia

class Document
{
Hashtable Properties ; //Key is the property name
}



class Media
{
Document document;
Status status
string this[string propertyName] //Return property value from the
document
{
}

}



I have a list of media and I would like to bind it to a grid In such a away
that
each property of the document will be displayed in a different column


Thanks in advance
 
J

Julia

No!!!

after loading the list with the media,all media in the list have the same
properties




James Curran said:
From the information given, it is impossible. Consider that Medium M1
has properties A & B, while Medium M2 has properties C & D. How could it
even draw the heading column, when it won't know what those heading will be
until it's finished processing every row?

--
--
Truth,
James Curran
[erstwhile VC++ MVP]

Home: www.noveltheory.com Work: www.njtheater.com
Blog: www.honestillusion.com Day Job: www.partsearch.com

Julia said:
class Document
{
Hashtable Properties ; //Key is the property name
}



class Media
{
Document document;
Status status
string this[string propertyName] //Return property value from the
document
{
}

}



I have a list of media and I would like to bind it to a grid In such a away
that
each property of the document will be displayed in a different column


Thanks in advance
 
F

Frans Bouma [C# MVP]

Julia said:
class Document
{
Hashtable Properties ; //Key is the property name
}



class Media
{
Document document;
Status status
string this[string propertyName] //Return property value from the
document
{
}

}



I have a list of media and I would like to bind it to a grid In such a away
that
each property of the document will be displayed in a different column

Implement ICustomTypeDescriptor on Document. It comes down to the fact
that you have to supply a PropertyDescriptorCollection, which for each
property you want to expose a PropertyDescriptor instance. You therefore
have to implement a class derived from PropertyDescriptor.

For each entry in the hashtable 'Properties' you then create a property
descriptor and return it in Document.GetProperties. When you then bind a
collection of Document instances to a grid, each property in the
document will show up as a column.

Be aware though that all document instances in the collection you bind
have to have the same properties.

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