C# class design

  • Thread starter Thread starter dmovva
  • Start date Start date
D

dmovva

Hi all,
I am working on a class and having a problem with the design.

I have Class2; The columns(properties) of this column are to be
determined at runtime. I have gridview control that I want to bind a
list of objects of this class to.

For example. If I have 2 accounts selected at runtime then the Gridview
has to look like this.

Iteration Account1 Account2
1 act1.Val1 act2.val1
2 act1.val2 act2.val2

If I have 3 accounts


Iteration Account1 Account2 Account3
1 act1.Val1 act2.val1 act3.val1
2 act1.val2 act2.val2 act3.val2


Can someone help me with the design please.

Thanks
Dilip
 
dmovva said:
Hi all,
I am working on a class and having a problem with the design.

I have Class2; The columns(properties) of this column are to be
determined at runtime. I have gridview control that I want to bind a
list of objects of this class to.

For example. If I have 2 accounts selected at runtime then the Gridview
has to look like this.

Iteration Account1 Account2
1 act1.Val1 act2.val1
2 act1.val2 act2.val2

If I have 3 accounts


Iteration Account1 Account2 Account3
1 act1.Val1 act2.val1 act3.val1
2 act1.val2 act2.val2 act3.val2


Can someone help me with the design please.

Thanks
Dilip

When using dynamic data such as this, I would use a DataSet to store the
data in.

HTH,
Mythran
 
Either you have to fill the cells manually using a simple row/column setup
and a heap of UI code, or you need to master the component model.

For the latter:
Specifically, if you implement ICustomTypeDescriptor, you can implement
GetProperties to yield each column; there is a SimplePropertyDescriptor that
you can inherit from to define runtime properties. You would return a
PropertyDescriptor for each logical column (with supporting code to
read/write the values to your underlying object model). To add confusion,
under some circumstances you actually need to implement ITypedList (at the
collection level, along with IList and a typed "this" [indexer]. And to
provide full runtime support you could do to implement IBindingList.

To be honest, none of these are trivial, but there are some great examples
on google. On the plus: you get less UI code, and you can even leverage the
UITypeEditor support at the client (i.e. like the properties grid in visual
studio). On the minus, it can be a fair amounnt of work.

Another option is to dynamically define a DataSet, as this does the above
things for you. Not as pleasing, but it'll work. I have recently completed a
fully class-based, dynamic (runtime) property model, but it is more code
than I could ever post here.

Marc
 
Actually you can alter the number of columns in a GridView at page load time:

MyGridView.Columns.Add(c);
 
Back
Top