CTreeCtrl problem #2

Hi,
I have in my application 2 CTreeCtrl.
Sometimes, I don't know why, some entries that are supposed to appear in
tree1, appear in tree2.
The first reason for this is that I have a bug! The second reason is shown
below.
Here is what I discovered:
The handles of the items for both trees seem to be shared.
My bug is that I try to insert an item into tree1 and the parent handle is
in tree2.
To do this I use tree1->InsertItem....
I expected that if the parent doesn't exist in tree1, nothing will happen.
The result is that the item is inserted in tree2 under the parent
handle!!!!!!!!!!
To be a little more confused, if tree1 had no items at the time I want to
insert that item, then nothing happen, tree2 do not insert the item!!!!!!

Now, what I have to do is to find my bug (of course) but I'm a little bit
concerned that items can be added into another tree than the one expected.
I experienced the problem with 2 CTreeCtrl in the same dialog or in
different panes in a CFrameWnd.

--
Normand


0
NoEmail9920 (149)
7/24/2004 3:58:23 PM
vc.mfc 33608 articles. 0 followers. Follow

6 Replies
581 Views

Similar Articles

[PageSpeed] 23

On Sat, 24 Jul 2004 11:58:23 -0400, "Normand" <NoEmail@Please.com>
wrote in <BGvMc.19173$Fj.921162@news20.bellglobal.com>:

>I have in my application 2 CTreeCtrl.
>Sometimes, I don't know why, some entries that are supposed to appear in
>tree1, appear in tree2.
>The first reason for this is that I have a bug! The second reason is shown
>below.
>Here is what I discovered:
>The handles of the items for both trees seem to be shared.
>My bug is that I try to insert an item into tree1 and the parent handle is
>in tree2.
>To do this I use tree1->InsertItem....
>I expected that if the parent doesn't exist in tree1, nothing will happen.
>The result is that the item is inserted in tree2 under the parent
>handle!!!!!!!!!!
>To be a little more confused, if tree1 had no items at the time I want to
>insert that item, then nothing happen, tree2 do not insert the item!!!!!!
>
>Now, what I have to do is to find my bug (of course) but I'm a little bit
>concerned that items can be added into another tree than the one expected.
>I experienced the problem with 2 CTreeCtrl in the same dialog or in
>different panes in a CFrameWnd.

How are you binding the instances of CTreelCtrl to the actual windows?

-- 
Charles Calvert             |  Software Design/Development
Celtic Wolf, Inc.           |  Project Management
http://www.celticwolf.com/  |  Technical Writing
(703) 580-0210              |  Research
0
cbciv (23)
7/24/2004 6:27:24 PM
Hi Charles,
long repost, sorry.
I use 2 CTreeCtrl in my application in different panes but I reproduce the
problem in a simple dialog frame.
I add 2 CTreeCtrl in design mode.
I create 2 CTreeCtrl variables with ClassWizard
When I hit a button (button 2), here is the function being called:
OnButton2()
{
 TVINSERTSTRUCT tvstruct;
 tvstruct.item.mask = TVIF_TEXT | TVIF_CHILDREN;
 tvstruct.item.pszText = "Test 1";
 tvstruct.hParent = NULL;
 tvstruct.item.cChildren = 1;
 tvstruct.hInsertAfter = TVI_LAST;
 m_coTree1.DeleteAllItems();
 HTREEITEM hti = m_coTree1.InsertItem(&tvstruct);
 m_coTree1.InsertItem(&tvstruct);  // 2 items with "Test 1" in tree 1   OK

 tvstruct.item.pszText = "Test 2";
 m_coTree2.DeleteAllItems();
 HTREEITEM hti2 = m_coTree2.InsertItem(&tvstruct);
 m_coTree2.InsertItem(&tvstruct);  // 2 items with "Test 2" in tree 2   OK

 tvstruct.item.pszText = "Test 1.1";
 tvstruct.hParent = hti;
 tvstruct.item.cChildren = 1;
 tvstruct.hInsertAfter = TVI_LAST;
 HTREEITEM hti11 = m_coTree1.InsertItem(&tvstruct);  // Inserted in tree 1
under the first "Test 1"   OK
 HTREEITEM hti21 = m_coTree2.InsertItem(&tvstruct);  // Inserted in tree 1
under the first 'Test 1"    STRANGE

 tvstruct.item.pszText = "Test 2.1";
 tvstruct.hParent = hti2;
 tvstruct.item.cChildren = 1;
 tvstruct.hInsertAfter = TVI_LAST;
 HTREEITEM hti211 = m_coTree2.InsertItem(&tvstruct); // Inserted in tree 2
under the first "Test 2"   OK
// m_coTree1.DeleteItem(hti2);  //For Result 1 I don't execute that line.  I
did for Result 2
 HTREEITEM hti111 = m_coTree1.InsertItem(&tvstruct); // Inserted in tree 2
under the first "Test 2"   STRANGE
}

This is what I get for the trees, everytime I hit button 2:
*** Result 1 ***
tree1:
    Test 1
        Test 1.1
        Test 1.1
    Test 1
tree2:
    Test 2
        Test 2.1
        Test 2.1
    Test 2
In both trees, I have to expand myself their first item to see the children
of those items.

See what happen if I execute that line before the last one:
       m_coTree1.DeleteItem(hti2);
*** Result 2 ***
tree1:
    Test 1
        Test 1.1
        Test 1.1
    Test 1
tree2: (empty)
As in the first test, I have to expand manually.

The fun is only beginning.  Now, if I click button 2 more than once and that
I expand the first item between clicks, I have always the same result as in
Result 2 for tree 1 no matter how many times I hit button 2.  But for tree2,
after 6 times, "Test 2" appears and the horizontal scroll appears too.  From
there, everytime I hit button 2, the horizontal scroll show like mor items
are available but there is none.
If I don't expand the first item from tree1, tree1 is cleared after another
click on button 2.  But tree 2 is doing the same thing.

I had surprises but I guess that repost is long enough.
But let say that if you use a HTREEITEM inserted in a tree (tree1 for
example) on another tree (say tree2),  strange things happen.
Sorry again for that long repost.

Normand.

"Charles Calvert" <cbciv@yahoo.com> a �crit dans le message de news:
8da5g0dfvh8q13sgpln78c1ssamp785goc@4ax.com...
> On Sat, 24 Jul 2004 11:58:23 -0400, "Normand" <NoEmail@Please.com>
> wrote in <BGvMc.19173$Fj.921162@news20.bellglobal.com>:
>
> >I have in my application 2 CTreeCtrl.
> >Sometimes, I don't know why, some entries that are supposed to appear in
> >tree1, appear in tree2.
> >The first reason for this is that I have a bug! The second reason is
shown
> >below.
> >Here is what I discovered:
> >The handles of the items for both trees seem to be shared.
> >My bug is that I try to insert an item into tree1 and the parent handle
is
> >in tree2.
> >To do this I use tree1->InsertItem....
> >I expected that if the parent doesn't exist in tree1, nothing will
happen.
> >The result is that the item is inserted in tree2 under the parent
> >handle!!!!!!!!!!
> >To be a little more confused, if tree1 had no items at the time I want to
> >insert that item, then nothing happen, tree2 do not insert the item!!!!!!
> >
> >Now, what I have to do is to find my bug (of course) but I'm a little bit
> >concerned that items can be added into another tree than the one
expected.
> >I experienced the problem with 2 CTreeCtrl in the same dialog or in
> >different panes in a CFrameWnd.
>
> How are you binding the instances of CTreelCtrl to the actual windows?
>
> --
> Charles Calvert             |  Software Design/Development
> Celtic Wolf, Inc.           |  Project Management
> http://www.celticwolf.com/  |  Technical Writing
> (703) 580-0210              |  Research


0
NoEmail9920 (149)
7/24/2004 8:47:03 PM
>The handles of the items for both trees seem to be shared.

The underlying implementation as explained to me is that the tree
control is determined from the passed item handle rather than via the
directly passed window handle.

>My bug is that I try to insert an item into tree1 and the parent handle is
>in tree2.
>To do this I use tree1->InsertItem....
>I expected that if the parent doesn't exist in tree1, nothing will happen.
>The result is that the item is inserted in tree2 under the parent
>handle!

Yes, it seems mighty odd doesn't it.

>To be a little more confused, if tree1 had no items at the time I want to
>insert that item, then nothing happen, tree2 do not insert the item!!!!!!

I wasn't aware of that aspect, but I can imagine that it's a simple
safeguard test that's performed.

>Now, what I have to do is to find my bug (of course) but I'm a little bit
>concerned that items can be added into another tree than the one expected.

I'm afraid there's nothing that can be done unless MS redesign the
tree control or you add some additional code and data of your own to
ensure that the handle is associated with a particular tree control -
probably not worth the effort or overhead.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
7/25/2004 8:47:29 AM
Hi David,
There is one positive point to that.
As I said, I have a bug somewhere in my code and the effects were that both
CTreeCtrl did'nt always show what was expected.
It was difficult to reproduce intentionnaly.  In fact I never success to do
that!
Before I was looking where I could use any CTreeCtrl in the wrong way.  No
results.
But now I will check for bad HTREEITEM usage in CTreeCtrl's.  This is a big
difference.  Now I will find the bug (I hope!) and I'll be able to reproduce
the bug.

Sometimes you need to understand what happen internally when you use APIs.
This was the case here.

Normand.

"David Lowndes" <davidl@example.invalid> a �crit dans le message de news:
pbs6g016n5k90ubomgr61in4lfelfjverh@4ax.com...
> >The handles of the items for both trees seem to be shared.
>
> The underlying implementation as explained to me is that the tree
> control is determined from the passed item handle rather than via the
> directly passed window handle.
>
> >My bug is that I try to insert an item into tree1 and the parent handle
is
> >in tree2.
> >To do this I use tree1->InsertItem....
> >I expected that if the parent doesn't exist in tree1, nothing will
happen.
> >The result is that the item is inserted in tree2 under the parent
> >handle!
>
> Yes, it seems mighty odd doesn't it.
>
> >To be a little more confused, if tree1 had no items at the time I want to
> >insert that item, then nothing happen, tree2 do not insert the item!!!!!!
>
> I wasn't aware of that aspect, but I can imagine that it's a simple
> safeguard test that's performed.
>
> >Now, what I have to do is to find my bug (of course) but I'm a little bit
> >concerned that items can be added into another tree than the one
expected.
>
> I'm afraid there's nothing that can be done unless MS redesign the
> tree control or you add some additional code and data of your own to
> ensure that the handle is associated with a particular tree control -
> probably not worth the effort or overhead.
>
> Dave
> --
> MVP VC++ FAQ: http://www.mvps.org/vcfaq


0
NoEmail9920 (149)
7/25/2004 1:17:45 PM
>Sometimes you need to understand what happen internally when you use APIs.

Yeah, that's certainly true in many circumstances, but especially here
where the behaviour is distinctly unintuitive.

All the best in finding the problem.

Dave
-- 
MVP VC++ FAQ: http://www.mvps.org/vcfaq
0
davidl7375 (2060)
7/25/2004 10:37:21 PM
Hi Normand,

Regarding on this issue, it appears the user should ensure that the hParent 
member of the TVINSERTSTRUCT is an item in the tree to which the new item 
is being inserted, as there are plenty of potential issues if this is not 
the case.  

After we checked the source code for TV_InsertItem(), found there is 
clearly the assumption that the hParent is in the same tree.  It would be 
nice if InsertItem returned NULL in this case, but it currently doesn't.

Thanks for your feedback on this problem, we really appreciate it very much 
and will pass the concern to the dev team.


Have a nice day!

Best regards,

Gary Chang
Microsoft Online Partner Support

Get Secure! - www.microsoft.com/security
This posting is provided "AS IS" with no warranties, and confers no rights.
--------------------

0
v-garych (605)
7/28/2004 5:20:07 AM
Reply:

Similar Artilces:

selection in CTreeCtrl
Hello, I have a Tree Control in my application that displays two types of items: type A and type B. I want to implement the following: 1. When user clicks on any item of type A it should be shown as selected and the previously selected item will be deselected - it is actually the default behavior. 2. When user clicks on any item of type B - nothing should happen: the previously selected item remain selected and the clicked item remains deselected. So, actually, I want that the items of type B will never highlighted with a blue band. How can do it? Thanks, Mark. -- Please ...

offline sync problem
Yesterday I had a customer's 8 register system lose internet connectivity, so all the registers went off-line. They are using RMS 1.2 SR3 on a SBS Professional 2003 Server with XP SP2 registers. When internet connectivity was restored today, all but one of the registers sync'd. On the register that did not, the last transaction in the batch was at about 7:40pm yesterday. No transactions were recorded after that time. I manually took the register off-line today and could not find any batch or blind-closed batch with any transactions after 7:40pm. I also checked, via MS Acce...

Linker problem compiling new project
I just installed Microsoft Visual Studios .NET 2003 on my Windows XP machine. I opened it up and started a new project. I pick Visual C++ as the language and Win32 Project as the project type. The wizard poped up and I hit finish. I have not done any of my own coding now. I tried to build the project but I got this error: fatal error C1083: Cannot open include file: 'windows.h': No such file or directory It is referenceing the file stdafx.h, which is automatically generated so I thought that it would add the path to the windows.h file automatically. At this time, I have not chan...

OE problem
Hi group Win XP Home OE v6 Mozilla (browser) This is what error I have when trying to post in NEWSgroup. Unable to poll for new messages on your HTTP server. Account: 'hotmail', Server: 'http://services.msn.com/svcs/hotmail/httpmail.asp', Protocol: HTTPMail, Server Response: 'Forbidden', Port: 0, Secure(SSL): No, Server Error: 998, Error Number: 0x800CCC33 Tried many things but unable to get past abov. My Net connection good...usinh hotmail via Mozilla. Terry Terry wrote: > Hi group > > Win XP Home > OE v6 > Mozil...

Sheet Tab name #2
Hi Does anyone know if there is a way to pick up the sheet name in a cell? Thanks Shona =MID(CELL("filename",A1),1+FIND("]",CELL("filename",A1)),255) Workbook needs to be saved before the above will work. You may wish to substitute the cellreference of the calling formula instead of A1, if there is a risk of Row 1 or Column A being deleted at some later date. "SS" <Student.13@uk.bosch.com> wrote in message news:cie62r$22d$1@ns1.fe.internet.bosch.com... > Hi > > Does anyone know if there is a way to pick up the sheet name in a cell...

Callout problems (not working at all)!
Dear all, We are having a lot of trouble to get a simple test Callout functionality to work. We used the standard microsoft online documentation as an example. We tested on several systems and still no results. We checked to make sure the CLSID of the COM+ object was the same as the one in the subscriber table of the metabase DB. Also changed the name in the subscriber table to match the one of the component as well as the application. When we delete the com-object, no exception is generated. This gives us the feeling that the COM object is never called. What are we doing wrong..... I'...

2 if statements?
Is it possible to have 2 IF statements in the same cell? Thanks, Carla Bradley carla.bradley(at)lgeenergy.com ...

Optimal settings for 2 PCs with Outlook 2003/same mail account?
Hey all... I've got a PC on my desk at work, and a laptop that goes home with me. Both access 2 of the same email accounts, and both should get all of the same emails. I set it up yesterday in the Advanced tab of More Settings that Outlook should leave a copy of the mail on the server, should be deleted after 3 days, and I also checked that it should be deleted after being deleted from the Deleted Items folder in Outlook. This morning I look on the laptop, and there are 5 copies of each email received overnight, and when I got in to the office and looked at the desktop, there was onl...

UPPER CASE PROBLEM
HI , CAN ANYONE HELP PLEASE? IT SEEMS QUITE SIMPLE BUT I CAN'T FIND A SOLUTION. I HAVE AN EXCEL FILE WHICH IS UPDATED BY A MACRO EVERY DAY. IT CONTAINS A FEW COLUMNS AND SOME OF THEM ARE FORMATTED AS TEXT. I NEED TO VISUALIZE ALL THE TEXT INTO UPPER CASE. THANKS CINZIA You need to use the UPPER() function. As an example if you had the text "upper" in cell A1 and entered the formula =UPPER(A1) in another cell then the result would display as "UPPER". It may be worth amending the Macro to change the text to uppercase when it runs. >-----Original Message...

a problem
there is an A column has 1500 line and a B column has 1700 line and B column already has A column entries, there just 200 entries are different i want to find 200 diffrent entries. how can i find? Conditional formatting. Select B1:B 1700. Menu Format>Conditional Formatting Change Condition 1 to Formula Is Add a formula of =ISNUMBER(MATCH(B1,$A:$A,0)) Click Format Select the pattern tab Choose a colour OK OK -- HTH Bob Phillips (there's no email, no snail mail, but somewhere should be gmail in my addy) "bakalim" <yok@yok.com> wrote in message news:ueQ7R7CTH...

Queue problem and incoming email directed at crm
I have CRM setup in a test domain fine mostly but asides from replies from SFO to a test account, I dont think all aspects of email routing is fine - but the email router must be least part working in order to be able to store CRM history and email out. I could be wrong on this! I can send emails from CRM to the test account ( not a crm user, but has been setup against a account/contact) and they show in the contact activity history. I can see the replies on the CRM test user in SFO (so they get as far as the account used by CRM), but they do not show in CRM against activity for contact. If ...

problem with automatic forward
hello i have recently upgrade win2000/exch5.5 with Win2003 and Exchange Server 2003 we have another server as SMTP gateway (as smarthost in SMTP connector options) i have created some contacts with external e-mail address for some users to leave messages both in mailbox and forward address Autoatic Forward doesn't work (it works only with internal address) all messages to external address remain in SMTP connector Queue please, have you any idea ?? thank you ...

Pick List Problem
I posted this a few days ago, but Don't think I explained myself very well. Can anybody help me with this issue. I am trying to select an item from a pick list (Cell A1) to be inserted into another cell and be able to automatically copy the adjacent cell (A2) value to another cell. Example: This is the pick list Cell A1 Cell A2 PAPER HOLDER - LEVEL I (CHROME) $2.80 TOWEL BAR - 24" LEVEL I (CHROME) $2.80 TOWEL BAR - 18" LEVEL I (CHROME) $2.80 Once I choose the item from Cell A1 to fill in another cell location, I want the ad...

Can't update chart #2
Hello, I have a spreadsheet with 50 tabs. Each tab has a 6 month audit score that looks like this: MAR APR MAY JUN JUL AUG 100% 100% 100% 100% 100% 100% There is a bar graph linked to these cells on each tab. What I am trying to do is group the tabs together, then delete the MAR score, shift all cells to the left, then add a SEP score. The problem is... when I try to do that, the graph changes to only show APR MAY JUN JUL & AUG. I can't get it to automatically add SEP. I could do it individually but that would be very time consuming to do it for 50 ...

Custom View Problems
I have defined a custom view with some hidden columns and a filter on 1 column. I checked the box to remember hidden columns, rows, and filters. When I display the view, the filter does not seem to have any effect. If I click on the auto filter dropdown menu at the top of the column that has a filter, the correct filter item is highlighted and if I re-select it, the filter works. Is there some other setting I have to enable to get this to work correctly? Also, I have another custom view that unhides the hidden columns and sets the auto filter to "All" in order to get back to the ...

Plotting Problems #2
Hello, I have a user with Excel 2002 on an NT 4.0 system. He's having problems copying equations into certain cells. Instead of listing the equation, the source location is pasted in (=A5). He has General selected under Format-Cells-Numbers. Any ideas what could be the problem? Thanks in advance, -- Wes Not sure this will help, but I'd try EDIT>COPY while in the cell and then to see what is going on, EDIT>PASTE SPECIAL and see if it defaulting to something other than ALL, FORMULAS or VALUES. I'd also check FILE>PROPERTIES to see if it is read-only. If the s...

ODBC Problems
Never had this much of a problem. I moved to a new server per 878499. Everything went real well. Logged on to GP from the server and everything went fine. Created a system DNS source and tried connecting from workstations with error Connection Failed SQL State '08001 sql error 10060. Please help cause I need everything up and running by Monday morning What version/release of GP and what version of SQL? Frank Hamelly MCP-GP, MCT, MVP East Coast Dynamics www.eastcoast-dynamics.com get your GPtip42today at www.gp2themax.blogspot.com tstrop, Check this article: ht...

Bolding or Hilighting node in a CTreeCtrl
I am looking for a way of of bolding, hilighting, or changing the text color for one specific node in a CTreeCtrl. Is this possible? If so, how? You have use an owner draw tree control. Look in here for one: http://www.codeproject.com/treectrl/#Custom+Tree+Controls This one looks useful http://www.codeproject.com/treectrl/colortreectrl.asp AliR. <mr.porteiro.head@gmail.com> wrote in message news:1141668031.681508.117640@u72g2000cwu.googlegroups.com... > I am looking for a way of of bolding, hilighting, or changing the text > color for one specific node in a CTreeCtrl. Is t...

Root / Child Windows 2003 Exchange 2003 Permission Problem -- What permission is my account missing?
I have a root and child domain (root.company.com and child.company.com). Both root and child servers are running Windows 2003 SP1. I created a user account in the Root domain called "ROOT\SuperAdministrator". This user account a member of: - Administrators - Domain Admins - Domain Users - Enterprise Admins - Exchange Domain Servers - Exchange Enterprise Servers - Schema Admins Exchange 2003 is installed on a Windows 2003 SP1 box in the child domain. Using Exchange System Mananger, we delegated control so that "ROOT\SuperAdministrator" is a "Full Exchange Adminis...

Problem Backing Up PST With Xcopy
Before I upgraded to Office 2003, I used a xcopy batch file from the command line to copy everything to a backup drive. Even when Outlook 2003 is never started xcopy will not run because somehting has locked the PST file. What is it and how do I unlock the file for backup? Do you have a PDA in its cradle? --� Milly Staples [MVP - Outlook] Post all replies to the group to keep the discussion intact. After searching google.groups.com and finding no answer: Ken <anonymous@discussions.microsoft.com> asked: | Before I upgraded to Office 2003, I used a xcopy batch | file from the comm...

How to create stand alone file dialog #2
How can I create a stand alone file dialog application? for example, when i click a .exe file, just pop up a file dialog box. Thanks! Dade ...

XmlReader Question #2
Hi, I am using an XmlTextReader to read an xml file. It may happen that the file is present in the disk, but it may be empty (0 bytes). I would like to find out whether the xml file contains a valid root node or not. How do I do this? This is what I need if(File.Exists(fileName)) { XmlTextReader xmReader = new XmlTextReader(fileName); //How do I find out whether this xml document contains a Root node named "ROOT_NODE" or not? } CGuy You can loop with the reader through the document until you find the first element node and then check if node's name is not R...

Security problem
My diagnostics show a security problem: http://live.iobit.com/report.php?PHPSESSID=ed4c588d953ee52139535459f16abac9 But I don't know what to do with the readout. I need help. TIA ...

Converting files #2
Hi I have a file with a *.lis extension which I would like to import into excel for analysis. However when I do this it is not formatted correctly and requires a significant amount of work to get it into the right colums etc. Can anyone help please as this is driving me mad ! Thanks David Hi very difficult to say as you don't provide much information about your data file: - what program has created it - some example rows of data (plain text - no attachment please) - etc -- Regards Frank Kabel Frankfurt, Germany "Dave" <dave@fsnet.co.uk> schrieb im Newsbeitrag news:9db...

Where Does Outlook Store Info? Computer Problems
Recently the power supply, motherboard, & CPU on my computer died. So I had a new motherboard, power supply, CPU and hard drive installed. The new hard drive is larger and faster than the old one. This required that Windows XP, Microsoft Office, etc, had to be installed. But before any of that was done, the technician took everything off the old hard drive and saved it into a file on the new one. All of the old data files, etc, are supposed to be there. My question, though, is how to find the address book and the saved emails that were on the old computer & put them into Outlook on the...