473,779 Members | 2,083 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

VB to C# TreeView problem

3 New Member
Hi,

I am trying to convert a VB.net code to C# .

it is to bind a treeview from a collection. but not finding a Collection which stores treenodes as object.

Cant use hashtable since it automatically sorts the data by key.

Can anybody tell me a collection which takes objects and doesn't sort it.

The code is as follows. can anybody convert this?
Expand|Select|Wrap|Line Numbers
  1. Private Sub TreeViewPopulation(ByVal ds As DataSet, Optional ByVal intParent As Integer = 0) 
  2. Dim TvwParent As New TreeNode
  3.  
  4. Dim TvwNode As New TreeNode Dim CollItems As New Collection 
  5. Try
  6.  
  7. tvw.Nodes.Clear()
  8.  
  9. For Each dr As DataRow In ds.Tables(0).Rows ''''assigning dataset values to a collection as node
  10.  
  11. TvwNode = New TreeNode(dr("Employee_Nm").ToString) 
  12. TvwNode.Tag = dr("Parent")
  13.  
  14. CollItems.Add(TvwNode, dr("Employee_Id")) 
  15. Next
  16.  
  17. For Each TvwNode In CollItems 
  18. TvwParent = Nothing
  19.  
  20. 'find parent of a node
  21.  
  22. If Val(TvwNode.Tag) <> intParent Then TvwParent = CType(CollItems.Item(TvwNode.Tag.ToString), TreeNode) 
  23. If Not TvwParent Is Nothing Then
  24.  
  25. 'add child node to its parent node
  26.  
  27. CType(CollItems.Item(TvwNode.Tag.ToString), TreeNode).Nodes.Add(TvwNode.Clone) 
  28. Else
  29.  
  30. tvw.Nodes.Add(TvwNode) 'add node to Treeview
  31.  
  32. End If
  33.  
  34. Next
  35.  
  36. Catch ex As Exception MsgBox("TreeView Population Error", MsgBoxStyle.Critical) 
  37. End Try
  38.  
  39. End Sub
  40.  
plz dont give me the online code converter

Thanks in Advance, Balu
Feb 15 '08 #1
6 1432
Plater
7,872 Recognized Expert Expert
Anything in the System.Collecti ons namespace would be fine?
Maybe:
System.Collecti ons.Generic.Lis t<TreeNode>
The functionality should be roughly the same.
Feb 15 '08 #2
Frinavale
9,735 Recognized Expert Moderator Expert
Hi Balu,
Welcome to theScripts!

In order to help answer your questions more quickly please provide a meaningful Title for any threads you start (your title should reflect the problem your having).
Check out the Posting Guidelines for a set of rules that we follow here and especially take a look at the section on Please Use Appropriate Titles for New Threads. This not only helps us to answer your question more quickly but also helps to ensure that other members, and the general public, will have a better chance of finding answers to any similar questions.

Since you're posting in the .NET forum I also recommend you check out the stick post about how to Get a Faster Answer To Your Question for some tips on good titles in this forum.


Thanks!

-MODERATOR Frinny
Feb 15 '08 #3
balurajeev84
3 New Member
Anything in the System.Collecti ons namespace would be fine?
Maybe:

The functionality should be roughly the same.
i cant access System.Collecti ons.Generic.Lis t<TreeNode>
Feb 15 '08 #4
balurajeev84
3 New Member
Anything in the System.Collecti ons namespace would be fine?
Maybe:
System.Collecti ons.Generic.Lis t<TreeNode>
The functionality should be roughly the same.
i didnt get System.Collecti ons.Generic.Lis t<TreeNode>
Feb 15 '08 #5
Frinavale
9,735 Recognized Expert Moderator Expert
You're code is not completely valid. You have a line on which you have 2 Dim statements (this is not valid in VB ...since VB doesn't use ";"'s there's no way for the compiler to know what the end of the statement is)

Have you taken a look at the TreeNode Class? It has an example on how to manipulate TreeNodes in both C# and VB.NET.

-Frinny
Feb 15 '08 #6
Plater
7,872 Recognized Expert Expert
i didnt get System.Collecti ons.Generic.Lis t<TreeNode>
Are you sure you're in .NET?

In the solution explorer, under references, there should be some namespaces listed.
Make sure that "System" is one of them.
Feb 15 '08 #7

Sign in to post your reply or Sign up for a free account.

Similar topics

4
7599
by: Ian Powell | last post by:
Hi I've got objects in an sorted ArrayList like: P:\ P:\\DOCS P:\\i386 P:\\i386\ASMS P:\\i386\ASMS\1000 P:\\i386\ASMS\1000\MSFT
0
1779
by: Björn Bengtsson | last post by:
Hello! I have an urgent problem concerning ASP.NET, ADO.NET, SQL Server, XML and the TreeView control. I have two tables; one describing the products and one describing their relationships. A product may consist of multiple other products. So far everything is great. But one product may exist as a subproduct to multiple parent products. My tables:
4
10140
by: Karim El Jed | last post by:
Hi, I'm trying to expand a special Node of my TreeView from Codebehind. I have a TreeView on a page for navigating to another site. On the other tsite here is the same TreeView more precisely a new TreeView with the same nodes ;) So I would like to keep the expanding state of the first Tree for the second one on the next page. At least the last selected node (path will be saved in query string) should be expanded.
14
6835
by: Evan Kontos | last post by:
I am trying to implement a Treeview w/an XML file and I even copied and pasted examples from MSDN but can't get them to work. Any suggestions welcome. XML File <TREENODES> <TREENODE TEXT="Document-1"> <TREENODE TEXT="Folder-1" EXPANDED="true"> <TREENODE TEXT="Document-2" />
4
2862
by: Jeff Beem | last post by:
I have a class that inherits from TreeView. The treeview has tooltips for the nodes but they're showing up behind the form. Has anyone seen this? Are there any known fixes? Thanks in advance, Jeff Beem
3
3830
by: christof | last post by:
I've got a really easy problem, please help me: There are two pages in one I'm creating a TreeView like that: TreeView dbTree = new TreeView(); TreeNode dbTreeRoot = new TreeNode("Root"); dbTree.Nodes.Add(dbTreeRoot); .. ..
3
1638
by: William Sullivan | last post by:
I desperately want to replace my hand-made ajax treeview with the 2.0 TreeView. The webpage I'm designing uses the postbacks to dynamically fill the treeview. The reason why I'm doing this is because my tree is ENORMOUS. It can possibly hold millions of nodes. The problem is keeping this treeview constrained as a user clicks through the nodes. I've tried putting it in a DIV with a set width and height, but the problem is that when you...
8
12776
by: Matt MacDonald | last post by:
Hi All, I have a form that displays hierarchical categories in a treeview. Ok so far so good. What I was to do is have users be able to select a node in the treeview as part of filling out the form. I only want to allow single selection, so using checkboxes is out of the question. It works as is, but it makes the form very cumbersome if every time that a user selects a node, the whole page has to reload. Is there a way to have a node...
1
3603
by: Nikron | last post by:
Hi, I'm having an issue with the ASP.NET 2.0 Treeview control and persisting its' state accross requests. My Control is embedded within a master page and is used for site navigation. My problem is that the user wants to know which page they are currently on and therefore I need to highlight the selected node. The problem is I lose state whenever the user selects a node and is redirected to another page. Thanks in advance
0
2169
by: bsturg21 | last post by:
Hello, I have an app that has a custom treeview which inherits the base treeview class and I am having a problem with the way the treeview is being redrawn. Each node in the treeview represents a folder, and this problem began when I added the functionality to have a ghost image of the folder when it is dragged and dropped to another location in the treeview. My code to create the ghost image is as follows: this.NodeToBeDeleted =...
0
9474
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can effortlessly switch the default language on Windows 10 without reinstalling. I'll walk you through it. First, let's disable language synchronization. With a Microsoft account, language settings sync across devices. To prevent any complications,...
0
10137
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
9928
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
8959
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7483
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
5373
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
0
5503
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
4037
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2867
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.