DataGridView & Dynamic Properties

R

Rob

Dear All,

I have a class that exposes a few properties. These properties are used in a
DataGridView. The code for that is shown bellow. The problem is that I also
need to show data/columns/properties in the DataGridView that are not known
at compile time. The total number of these data/columns/properties is also
not known. So the question is how can I dynamically add properties (indexers
don't seem to work) so that DataGridView can show all of them? What other
ideas do you have?

class CDataSource
{
public DateTime DateAndTime {
get { return m_vDateTime; }
}
}

//Data source is a list of CDataSource instances
ArrayList vDataSource = new ArrayList();
CDataSource vEntry = new CDataSource;
vDataSource.Add(vEntry)

dataGridView.AutoGenerateColumns = false;
dataGridView.DataSource = m_avDataSource;
DataGridViewTextBoxColumn vDate = new DataGridViewTextBoxColumn();

vDate.Name = "Time";
vDate.DataPropertyName = "DateAndTime";
dataGridView.Columns.Add(vDate);

Regards,
Rob
 

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