Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations SkipVought on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Treeview and Simple Dataset 1

Status
Not open for further replies.

Genimuse

Programmer
May 15, 2003
1,797
0
0
US
I've done a bunch of searching, but I can tell that my fundamental lack of understanding of treeview nodes is keeping me from putting this together.

I've got a simple dataset with a view that looks like this:
Code:
GameID Game.Name DeckID Deck.Name VersionID Version.Name	
  1    Candyland    1	Movement      1     First Attempt
  1    Candyland    1   Movement      2     Second Attempt	
  1    Candyland    2   Bonus         3     Alpha
  2    Monopoly     3   Community     4     Initial Attempt	
  2    Monopoly     4   Chance        5     Starter Version	
  2    Monopoly     5   Properties    6     1.0
  2    Monopoly     5   Properties    7     1.1
  2    Monopoly     5   Properties    8     2.0
and I want a treeview that looks like this:
Code:
Candyland
  |-Movement
  | |-First Attempt
  | |-Second Attempt
  |-Bonus
    |-Alpha
Monopoly
  |-Community
  | |-Initial Attempt
  |-Chance
  | |-Starter Version
  |-Properties
    |-1.0
    |-1.1
    |-2.0
I'd planned to do a simple roll through the table, looking to see if GameID, DeckID, or VersionID changed, and would just go "up" or "down" a level in the treeview and add a node at the appropriate place.

Unfortunately, I don't get how to go deeper or more shallow, as it were... how to set what parent I'm adding a given child under. Referencing it, I guess.

Any pointers, even if it's just on understanding the treeview control better? I've read a bunch of stuff in MSDN and via Google and here, but it seems the thickness of my skull is proving to be a problem.
 
Yes your skull is a problem but it could be an age thing too ;-).

Now your "little" problem. If your data is sorted the way it should be then you shouldn't have a problem. Is it?

something like this. Untested. All disclaimers, but if it kills somebody I want the case.

Code:
public sub beginsomething()
  dim firstnode as new treenode
dim secondnode as new treenode
dim thirdnode as new treenode
  firstnode.text = datatablewithdata.rows(0).item("gamedata")
  secondnode.text = datatablewithdata.rows(0).item("deckname")
thirdnode.text = datatablewithdata.rows(0).item("versionname")
  for _int as integer = 1 to datatablewithdata.rows.count - 2
     if datatablewithdata.rows(_int).item("gamedata").equals(datatablewithdata.rows(_int-1).item("gamesata") then
       firstnode = new treenode
       firstnode.text = datatablewithdata.rows(0).item("gamedata")
       secondnode.text = datatablewithdata.rows(0).item("deckname")
       thirdnode.text = datatablewithdata.rows(0).item("versionname")
       firstnode.nodes.add(secondnode)
       secondnode.nodes.add(thirdnode)
       treeview1.nodes(firstnode)
     else
       if datatablewithdata.rows(_int).item("deckname").equals(datatablewithdata.rows(_int-1).item("deckname") then
         secondnode = new treenode
         secondnode.text = datatablewithdata.rows(0).item("deckname")
         thirdnode.text = datatablewithdata.rows(0).item("versionname")
         secondnode.nodes.add(thirdnode)
         firstnode.nodes.add(secondnode)
       else
       if datatablewithdata.rows(_int).item("versionname").equals(datatablewithdata.rows(_int-1).item("deckname") then
         thirdnode = new treenode
         thirdnode.text = datatablewithdata.rows(0).item("versionname")
         secondnode.nodes.add(thirdnode)
       else
           messagebox.show("Houston we have a problem")
         end if
       end if
     end if
  next
end sub

end sub

That looks bad, but I think it should work for the data given.

Christiaan Baes
Belgium

"My old site" - Me
 
Chrissie, have I mentioned lately that I love you? It's true.

That said, I don't quite follow how these nodes get added to TreeView1. I see the line that says:
Code:
treeview1.nodes(firstnode)
but that isn't an assingment or anything, right? Don't they also need to be added somehow in the other two if-then cases?
 
First of all does it work?

secondnode = new treenode
secondnode.text = datatablewithdata.rows(0).item("deckname")
thirdnode.text = datatablewithdata.rows(0).item("versionname")
secondnode.nodes.add(thirdnode)
firstnode.nodes.add(secondnode)

here I create a new seconnode and then change the text of secondnode and thirdnode then I add secondnode to firstnode and thridnode to secondnode.

It's like a form with controls and of those controls (for example a panel als has controls. In this case a treeview has nodes but every node also has childnodes.

Christiaan Baes
Belgium

"My old site" - Me
 
Based on the context
Code:
       firstnode.nodes.add(secondnode)
       secondnode.nodes.add(thirdnode)
       treeview1.nodes(firstnode)
I'm thinking this ought to read
Code:
       firstnode.nodes.add(secondnode)
       secondnode.nodes.add(thirdnode)
       treeview1.nodes[COLOR=red].add[/color](firstnode)

Of course if it works, then I'm wrong. :)

Bob
 
No, it's pretty basic, limited to "intelligent, sensitive" people like you and me. :)
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top