Select a tree item when first created - Programmer

This is a discussion on Select a tree item when first created - Programmer ; I use a CTreeCtrl inside a CTreeView. First I create a tree and it is displayed well. I want to select a certain item when the application loads and I can't do it. I noticed that only if the user ...

+ Reply to Thread
Results 1 to 4 of 4

Thread: Select a tree item when first created

  1. Select a tree item when first created

    I use a CTreeCtrl inside a CTreeView. First I create a tree and it is
    displayed well.
    I want to select a certain item when the application loads and I can't
    do it. I noticed that only if the user clicks on some item first, the
    application can change that selection to something else with
    HTREEITEM someItem;
    ..
    ..
    GetTreeCtrl().SelectItem(someItem);

    but if he doesn't click on anything (And no item is selected in the
    tree) then the SelectItem is meaningless...

    What can be done?
    thanx


  2. Re: Select a tree item when first created

    alexrait@gmail.com wrote:
    > I use a CTreeCtrl inside a CTreeView. First I create a tree and it is
    > displayed well.
    > I want to select a certain item when the application loads and I can't
    > do it. I noticed that only if the user clicks on some item first, the
    > application can change that selection to something else with
    > HTREEITEM someItem;
    > .
    > .
    > GetTreeCtrl().SelectItem(someItem);
    >
    > but if he doesn't click on anything (And no item is selected in the
    > tree) then the SelectItem is meaningless...
    >
    > What can be done?
    > thanx


    I normally store the HTREEITEM(s) returned when populating the control
    with InsertItem, then call SelectItem(MY_HTREEITEM)

    For example -

    HTREEITEM myItem = m_TreeCtrl.InsertItem("My Item");
    m_TreeCtrl.SelectItem(myItem);

    Also, you may not see the selection if the control doesn't have the
    focus. You can set the 'Always Show Selection' option in the dialog
    properties to true to always see it.

    Hugh


  3. Re: Select a tree item when first created

    Actually I don't have a dialog.. I use the tree view directly.. that
    is an SDI application.
    And I can't find such an option in the GetTreeCtrl() properties


  4. Re: Select a tree item when first created

    alexrait1 wrote:
    > Actually I don't have a dialog.. I use the tree view directly.. that
    > is an SDI application.
    > And I can't find such an option in the GetTreeCtrl() properties


    Try the TVS_SHOWSELALWAYS style.

    Hugh


+ Reply to Thread