View previous topic :: View next topic |
Author |
Message |
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Wed Dec 22, 2004 3:33 pm Post subject: HowTo: Use lParam within treeview TV_ITEMA node? |
|
|
I would like to use the lParam field within a TreeView TV_ITEMA node. When creating the TreeNode, I want to set the item.lParam field to be a coded value. (book num * 1000 + chapNum)
Genesis lParam = 1000
.. Gen.1 lParam = 1001
.. Gen.2 lParam = 1002
.. etc.
.. Gen.50 lParam = 1050
Exodus lParam = 2000
.. Exod.1 lParam = 2001
.. Exod.2 lParam = 2002
.. etc.
.. Exod.40 lParam = 2040
etc.
When I select the node, I would like to be able to acquire the lParam value to determine which specific chapter of which book was selected.
Can this be done? Is this what the "tag" field is for? |
|
Back to top |
|
|
Lynn
Joined: 27 Aug 2004 Posts: 89
|
Posted: Wed Dec 22, 2004 7:55 pm Post subject: |
|
|
Nevermind ...
I was able to utilize the "tag" field and accomplish what I wanted.
Code: |
class BookChapTag: Object
{
int bookNum;
int chapNum;
this(int b, int c)
{
bookNum = b;
chapNum = c;
}
int book() { return bookNum; }
int chap() { return chapNum; }
}
for (int bk = 1; bk <= 66; ++bk) {
char[] bookName = GetBookName(bk);
bookNode[bk] = new TreeNode(bookName);
bookNode[bk].tag(new BookChapTag(bk, 0));
chapSelectorTree.nodes.add(bookNode[bk]);
int chapCount = GetMaxChapInBook(bk);
for (int chapNum = 1; chapNum <= chapCount; ++chapNum) {
char[] chapName = GetBookNameAbbrev(bk) ~ "."
~ std.string.toString(chapNum);
TreeNode curNode = new TreeNode(chapName);
curNode.tag(new BookChapTag(bk, chapNum));
bookNode[bk].nodes.add(curNode);
}
}
private void OnChapTreeSelect(Object sender, TreeViewEventArgs ea)
{
Object o = ea.node.tag;
BookChapTag bct = cast(BookChapTag)o;
gCurBook = bct.book;
gCurChap = bct.chap;
LoadTextViewerWithChapter();
}
|
|
|
Back to top |
|
|
Chris Miller
Joined: 27 Mar 2004 Posts: 514 Location: The Internet
|
Posted: Thu Dec 23, 2004 8:56 am Post subject: |
|
|
There's tag, or you can derive from TreeNode:
Code: | class ChapTreeNode: TreeNode
{
int chapNum;
this(int chapNum, char[] text)
{
super(text);
this.chapNum = chapNum;
}
}
...
chapSelectorTree.nodes.add(new ChapTreeNode(1, "foo"));
|
|
|
Back to top |
|
|
|