Infralution Support Forum Index Infralution Support
Support groups for Infralution products
 
 FAQFAQ   SearchSearch   MemberlistMemberlist   UsergroupsUsergroups   RegisterRegister 
 ProfileProfile   Log in to check your private messagesLog in to check your private messages   Log inLog in 

Dynamically Add Columns

 
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support
View previous topic :: View next topic  
Author Message
Shailendra Baghel



Joined: 25 Nov 2005
Posts: 23

PostPosted: Tue Dec 06, 2005 3:43 pm    Post subject: Dynamically Add Columns Reply with quote

Can we Dynamically add column's to the Tree?

I have 3 columns (Col1,Col2,Col3) and the grid holds data for all the 3 columns. Now on right click on the Column Header, in the Context Menu, i choose Col4.
Lets assume that the context menu has been modified for this option and this column "Col4" was not associated with the Tree before.

The data for this column can be recieved from DataBinding objects at run-time.

Shailendra
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Tue Dec 06, 2005 9:24 pm    Post subject: Reply with quote

You can programmatically add columns at runtime by simply creating a new column object, setting the properties and adding it to the VirtualTree.Columns collection. You would need to also create and add a CellBinding for this column to each RowBinding you wished to display data in the column.

If you know upfront at design time what columns you might wish to be available it is better to create them in the designer and simply set the columns you don't want to be initially visible to have "Column.Active = false"). The user can then use the Customize Columns window to choose the columns they want - or you can programmatically set the column to be active.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Shailendra Baghel



Joined: 25 Nov 2005
Posts: 23

PostPosted: Thu Dec 08, 2005 5:32 am    Post subject: Dynamically Add Columns Reply with quote

you wrote

"You would need to also create and add a CellBinding for this column to each RowBinding you wished to display data in the column.
"
In my current prototype i have
1. A DataSource deriving grom IList. I have overridden Count() and this[index] methods only.
2. In the "DataBinding" tab of editor,i have added the above DataSource and 3 Objects each with some properties ( i.e columns ). These objects are "FirstLevel", "SecondLevel","ThirdLevel". These objects signify 3 Hiearchies.

Col1 | Col2 | Col3 ....
-----------------------------------
-Level1 | |
-Level2 | |
Level3 | |
+Level2 | |
+Level1 | |

3. Now i want to dynamically add columns. Assume i have a context menu for the Column Header and on right-click of it, i get a option to add column.
4. What goes inside the event handler of Option to add column?
5. Can you provide a psuedo-code?

Regds
shailendra
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Thu Dec 08, 2005 9:59 am    Post subject: Reply with quote

If you can set the column up at design time (with Active = false) then all you need to do is:

Code:
_myColumn.Active = true;


If you really need to add columns dynamically (because you don't really know what columns are possible) then your code would look something like:

Code:
_virtualTree.SuspendLayout();
Column col = new Column();
col.Caption = "My Column";
_virtualTree.Columns.Add(col);

// now add a binding for the column to those rows that support it
// where "MyProperty" is some property of the object you are binding to
//
_myRowBinding.CellBindings.Add(new ObjectCellBinding(col, "MyProperty"));

_virtualTree.ResumeLayout();

_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Shailendra Baghel



Joined: 25 Nov 2005
Posts: 23

PostPosted: Thu Dec 08, 2005 10:45 am    Post subject: Dynamically Add Columns Reply with quote

But this requires that you have defined a property named as "MyProperty" in the class whose object is "_myRowBinding".

In my case i have 200 columns. Each column has a name and a ID associated with it.

So i will have to write some 200 properties which is not a good design.

What i need is a function or a callback like the following
SomeFunction(int columnId)
{
// Get Data for this column for this row.
}

If possible,provide some puedo code.

Regds
Shailendra
Back to top
View user's profile Send private message
Infralution



Joined: 28 Feb 2005
Posts: 5027

PostPosted: Fri Dec 09, 2005 11:17 am    Post subject: Reply with quote

"MyProperty" was just intended to demonstrate that you could bind the column data to any exising property of your object - you don't have to add a special property called "MyProperty".

You can alternatively set the data to be displayed in each column programmatically by handling the GetCellData event - see the Programatic Binding sample project for an example of doing this.
_________________
Infralution Support
Back to top
View user's profile Send private message Visit poster's website
Display posts from previous:   
Post new topic   Reply to topic    Infralution Support Forum Index -> Virtual Tree Support All times are GMT
Page 1 of 1

 
Jump to:  
You cannot post new topics in this forum
You cannot reply to topics in this forum
You cannot edit your posts in this forum
You cannot delete your posts in this forum
You cannot vote in polls in this forum


Powered by phpBB © 2001, 2005 phpBB Group