Changing Node.Text property in TreeView control
Posted on 2004-09-20
Hi, I have a treeview control (V6) with nodes that show chapters with paragraphs. A chapternumber is supplied with each node, i.e:
1. Chapter One
1.1. Chapter One, Paragraph One
2. Chapter Two
2.1. Chapter Two, Paragraph One
2.2. Chapter Two, Paragraph Two
I have set the treeviews LabelEdit property to tvwAutomatic, so that the user can edit the titles.
The difficulty is that the user can now also edit the chapter number, which is not allowed.
I tried setting the SelectedItem.Text property to contain the title, stripped from its number in the BeforeLabelEdit-eventhandler, but found out that the treeview control fills an internal editbox with the entire text (ie 2.2. Chapter Two, Paragraph Two) prior to raising the BeforeLabelEdit-event. So, changing the node's text property won't help me...
Now, I'm this far that I got access to the internal edit control by using windows messages and changed the text in the editbox. Everything's working fine now: The user can edit only the title, save the pressing ENTER or ESC and the new title gets displayed again, supplied with its number...
The only thing is, and this finally brings me to the question:
The treeview places the internal edit control on top of the actual node. Since I stripped the number from the text in the edit control and not from the node's text property, the node's text property is longer than the edit control and therefore shows characters on the right side of the edit control.
Who knows of a way to either:
- Catch the escape-button pressed by the user in the edit control which ends the editing session and does not raise the AfterLabelEdit-event, so I could strip the number from the node's text property as well, and append the number again in case of an ESC.
- 'hide' this text on the right by enlarging the edit control, custom drawing, etc...
Thanks in advance,
ps: I don't think the code I used to send the messages is relevant here, but if you're interested I'll post it right here.