DaniWeb IT Discussion Community

DaniWeb IT Discussion Community (http://www.daniweb.com/forums/index.php)
-   C# (http://www.daniweb.com/forums/forum61.html)
-   -   Code Snippet: Using COM TreeView in C# Windows Forms (http://www.daniweb.com/forums/thread217036.html)

Shalvin Feb 14th, 2008 11:03 pm
Using COM TreeView in C# Windows Forms
 
TreeView was one of my favourite control in COM. It is well suited for creating Chart of Accounts, Hierarchical data and the like. Though there is a tree view in .Net I find it less flexible in comparison to COM TreeView.

The issue with using COM TreeView in C# is C# does not support optional parameters. Type.Missing it the way out.

  1. using MSComctlLib;
  2.  
  3. Node NodX;
  4.  
  5. private void Form1_Load(object sender, EventArgs e)
  6. { Object m = Type.Missing;
  7. Object i = "India";
  8. NodX = axTreeView1.Nodes.Add(ref m, ref m, ref i, ref i, ref m, ref m);
  9.  
  10. Object k = "Kerala"; Object rel = TreeRelationshipConstants.tvwChild;
  11. NodX = axTreeView1.Nodes.Add(ref i, ref rel, ref k, ref k, ref m, ref m);
  12.  
  13. Object ka = "Karnataka";
  14. NodX = axTreeView1.Nodes.Add(ref i, ref rel, ref ka, ref ka, ref m, ref m); Object ko = "Kochi"; NodX = axTreeView1.Nodes.Add(ref k, ref rel, ref ko, ref ko, ref m, ref m);
  15. NodX.EnsureVisible();
  16. }

All times are GMT -4. The time now is 10:35 am.

Forum system based on vBulletin Copyright ©2000 - 2009, Jelsoft Enterprises Ltd.
©2003 - 2009 DaniWeb® LLC