how to support multiple selection in treeview?

Hi,

It seems that CTreeCtrl doesn't support multiple items selection.  Is it 
correct?  Its member function GetSelectedItem() returns "the" selected item. 
Then how do we allow multiple selections?  Any help is appreciated.

JD 


0
jdt_young (239)
10/26/2007 3:38:50 AM
vc.mfc 33608 articles. 0 followers. Follow

4 Replies
2526 Views

Similar Articles

[PageSpeed] 32

>It seems that CTreeCtrl doesn't support multiple items selection.  Is it 
>correct?  Its member function GetSelectedItem() returns "the" selected item. 
>Then how do we allow multiple selections?  Any help is appreciated.

Although it's not multiple selection as such, each item can have a
check box if you use TVS_CHECKBOXES. See CTreeCtrl::SetCheck &
CTreeCtrl::GetCheck.

Dave
0
davidl7375 (2060)
10/26/2007 7:05:53 AM
"JD" <jdt_young@yahoo.com> wrote in
news:e6X36G4FIHA.4584@TK2MSFTNGP03.phx.gbl: 

> Hi,
> 
> It seems that CTreeCtrl doesn't support multiple items selection.  Is
> it correct?  Its member function GetSelectedItem() returns "the"
> selected item. Then how do we allow multiple selections?  Any help is
> appreciated. 

You have to do it yourself. Google "treeview multiple selection" and you'll 
get a number of hits. The next question is "is it worth it?". Dave's 
suggestion of using checkboxes instead is a good one.

Dave Connet
0
connet1 (33)
10/26/2007 2:33:45 PM
On Oct 26, 5:38 am, "JD" <jdt_yo...@yahoo.com> wrote:
> It seems that CTreeCtrl doesn't support multiple items selection.  Is it
> correct?  Its member function GetSelectedItem() returns "the" selected item.
> Then how do we allow multiple selections?  Any help is appreciated.

you could try something like....

void CMyTree::OnLButtonDown(UINT nFlags, CPoint point) {
  m_nClickFlags  = nFlags;
  HTREEITEM iClk = GetClickedItem();
  if (iClk) {
    if (m_fMultiselectable) {
      if (m_nClickFlags & MK_CONTROL) {
        // we change selection
        ChgSelection(iClk);
        return;
      }
    }
    // we set as selection
    SetItemState(iClk, TVIS_SELECTED , TVIS_SELECTED);
  } else CTreeCtrl::OnLButtonDown(nFlags, point);
}

HTREEITEM CMyTree::GetClickedItem() {
  DWORD dwPos = GetMessagePos();
  CPoint spt( LOWORD(dwPos), HIWORD(dwPos) );
  ScreenToClient(&spt);
  m_pt = spt;
  UINT test;
  HTREEITEM hti = HitTest(spt, &test);
  if ((hti != 0) && (test & (TVHT_ONITEM | TVHT_ONITEMRIGHT))) return
hti;
  if (hti == 0) {
    ClearSelection();
  }
  return 0;
}

void CMyTree::ChgSelection(HTREEITEM iClk) {
  if GetItemState(iClk, TVIS_SELECTED) == TVIS_SELECTED) {
    SetItemState(iClk, 0 , TVIS_SELECTED);
  } else {
    SetItemState(iClk, TVIS_SELECTED , TVIS_SELECTED);
  }
}

0
clqrq (258)
10/26/2007 3:53:35 PM
Hi rhavin,

Thanks for sharing your code.  I will modify it a little bit and reuse it. 
Thanks.

JD

".rhavin grobert" <clqrq@yahoo.de> wrote in message 
news:1193414015.621401.134400@19g2000hsx.googlegroups.com...
> On Oct 26, 5:38 am, "JD" <jdt_yo...@yahoo.com> wrote:
>> It seems that CTreeCtrl doesn't support multiple items selection.  Is it
>> correct?  Its member function GetSelectedItem() returns "the" selected 
>> item.
>> Then how do we allow multiple selections?  Any help is appreciated.
>
> you could try something like....
>
> void CMyTree::OnLButtonDown(UINT nFlags, CPoint point) {
>  m_nClickFlags  = nFlags;
>  HTREEITEM iClk = GetClickedItem();
>  if (iClk) {
>    if (m_fMultiselectable) {
>      if (m_nClickFlags & MK_CONTROL) {
>        // we change selection
>        ChgSelection(iClk);
>        return;
>      }
>    }
>    // we set as selection
>    SetItemState(iClk, TVIS_SELECTED , TVIS_SELECTED);
>  } else CTreeCtrl::OnLButtonDown(nFlags, point);
> }
>
> HTREEITEM CMyTree::GetClickedItem() {
>  DWORD dwPos = GetMessagePos();
>  CPoint spt( LOWORD(dwPos), HIWORD(dwPos) );
>  ScreenToClient(&spt);
>  m_pt = spt;
>  UINT test;
>  HTREEITEM hti = HitTest(spt, &test);
>  if ((hti != 0) && (test & (TVHT_ONITEM | TVHT_ONITEMRIGHT))) return
> hti;
>  if (hti == 0) {
>    ClearSelection();
>  }
>  return 0;
> }
>
> void CMyTree::ChgSelection(HTREEITEM iClk) {
>  if GetItemState(iClk, TVIS_SELECTED) == TVIS_SELECTED) {
>    SetItemState(iClk, 0 , TVIS_SELECTED);
>  } else {
>    SetItemState(iClk, TVIS_SELECTED , TVIS_SELECTED);
>  }
> }
> 


0
jdt_young (239)
10/26/2007 7:09:51 PM
Reply:

Similar Artilces:

Email multiple reports 11-16-07
Hello, I have a database where I need to send one email with several reports in it. Is there vb code to do that? On Fri, 16 Nov 2007 05:32:01 -0800, Brett <Brett@discussions.microsoft.com> wrote: Nothing built-in. DoCmd.SendObject can only send one report at a time. So you need to first save the reports (e.g. to PDF files), then create an email with multiple attachments. If you use Google, I'm sure you can locate some sample code. -Tom. >Hello, >I have a database where I need to send one email with several reports in it. > Is there vb code to do that? How about this...

Entering multiple literal values in a spreadsheet
Hi, I have to enter 6 digit numbers in a CSV file. When I re-open the CSV file, it will delete the leading 0s in the number. So 00001 looks like 1. If I enter =0001 in a cell, then the cell displays the literal value. This is good. However, how do I do this for 400 different cells in a row. THanx! Hi, If all you want to see when you open the file in Excel is 000001 or then you can apply the custom format 000000 to the cells - this will pack leading zeros in the display. If you want the numbers to actually contain the leading 0's then either format the range to Text before entering...

select path open file
In a text field a have more than one path. Can i select a path (with the mouse too) and open file with default windows program? ex \myfoder\photo1.jpg \myfoder\photo2.mdi \myfoder\file1.gpx i select with mouse \myfoder\file1.gpx and i desire open it thanks That would be possible Marco. You will need to be familiar with VBA to achieve it. One way would be to select the file name, and then click a toolbar button to open it. (You cannot use a command button on the form, because when you click the button, you would lose the selection.) This would involve creating a custom toolbar for th...

Outlook XP support for MS Mail?
Hi, I am using Outlook 2000 (which I bought as part of Office 2000). I use it in corporate/workgroup mode because I use Microsoft Mail for intra-office email. I use this because not all of the PC's on my LAN have an internet connection. I would like to upgrade to Office XP, but I am afraid that the newer version of Outlook will not support MS Mail. Can anyone tell me if this is true. If so, is there an alternative? Thank you, Paul Yep you can, although unsupported by Microsoft; http://www.outlook-tips.net/howto/msmail_xp.htm -- Robert Sparnaaij [MVP-Outlook] www.howto-outl...

Calculating Software Maintenance and Support Renewals
We are a software company that sells annual maintenance and support contracts. These contracts are typically purchased in years, however they can also be purchased in month increments - Does anyone know if this system can automate this so the reps don't have to figure out fractions. ...

Filter data by multiple drop down lists
I have a worksheet with the following columns: Item name, Item type, Item size + some other columns On the second worksheet I have the same columns in diferent order (Item type, Item size, Item name) but at every column I need drop down lists. I use data validation to produce the list for the items in the 'Item type' & 'Item size' columns. For the 'Item name' column I need a drop down, which is list, filtered by the previous two columns. Like first I select 'Item type' then 'Item size' and in the drop down list in clomun 'Item name' should a...

Same Sender Multiple Email
This is the setup that we have now. Example... > > > > Marketing department with following members > > 1. Marketing Mgr > > 2. Sale Specialist A > > 3. Sale Specialist B > > > > Note: all email recieved by salesspecialist B automatically Marketing Mgr > > recieved a copy. > > > > Collection Department with the ff > > 1. Colection Manger > > 2. Collectoin Assistant A > > 3. Collection Assistant B > > > > All email recieved by collection Assistant B, automatically Collection Mgr > > recieved a dupl...

Excel VBA
I would like to display the data autofilter selection criteri automatically someplace in a report. For instance, advise the users that the report only contains entrie where hours > 40, or where vendor contains smith. Is anyone aware of how this could be done? Sincerely Jim Palme -- Message posted from http://www.ExcelForum.com You could use a routine by Stephen Bullen from John Walkenbach's site: http://www.j-walk.com/ss/excel/usertips/tip044.htm "Jim Palmer <" wrote: > > I would like to display the data autofilter selection criteria > automatically some...

Support for India
Is there a Microsoft Money 2005 version for India? Thanks, Not a specific one, no. The international one would be the closest one, as that is the most generic. -- Glyn Simpson, Microsoft MVP - Money http://money.mvps.org Check http://money.mvps.org/faq for tips and fixes for MS Money. To send Microsoft your product wishes see http://money.mvps.org/wishes.aspx I do not respond to any unsolicited email regarding Money "gurmeet" <gurmeet@discussions.microsoft.com> wrote in message news:EE57EB02-2D2D-4342-8F0B-4CA26318D0DA@microsoft.com... > Is there a Microsoft Money 2...

mail merge problem: supported version of word is not installed...
when trying sending an email via mail merge, i'm getting the following error message: a supported version of microsoft word is not installed or the version cannot be obtained. outlook & word versions are: 2003 SP3. update rollup 2 server+client are installed. Any suggestions? ...

select record before and after, then calculate average.
I've got an intersting update query that I can't seem to figure out. What I am trying to do is identify the records where [O3ppm] is zero and update that value by averaging the hour before and the hour after. So for hour 1100, the value should be 0.04 by averaging the [O3ppm] value for the 1000 hour(before) and the 1200 hour(after). Any help is greatly appreciated. Here is a sample of the data: [ID] [DATE] [TIME] [O3ppm] 30898754 7/1/2005 0 0.02 30898755 7/1/2005 100 0.02 30898756 7/1/200...

twain support in publisher 2003
Can someone tell me if publisher 2003 supports twain for cameras and scanners. I am currently using publisher 2002 and this does not have twain support. This was available in earlier versions of publisher. I have no need to upgrade if this support is not included. There is a hotfix for the TWAIN issue for Office 2002. Description of the Office XP post-Service Pack 3 hotfix package for MSO.DLL: May 9, 2004 http://support.microsoft.com/default.aspx?scid=kb;en-us;829349 -- Mary Sauer MSFT MVP http://office.microsoft.com/ http://msauer.mvps.org/ news://msnews.microsoft.com "R. C. Kelle...

Cell value depends on Combobox selection
I'm trying to create a price list using combo boxes for the user t select the number of items for each product. For each product, the user has to choose the number of items via combo box. The combo box is being filled from cells K1:K6 (through th ListFillRange in the properties), the LinkedCell in order to hold th selection output is M1. The various prices are listed in cells L1:L6. What do I need to do in order to dynamically display the product pric in a specific cell depending on the selection from the combo box? Many thanks, Su -- Message posted from http://www.ExcelForum.com S...

multiple copy one paste
As I use all Windows functions, I long for a way to do multiple copies, then one paste. I call it Copy Add. This would allow me to copy from diverse documents and paste to one destination. As an example, I have an email with three attachments. I use the information as a running record of transactions I have sent to a customer. I open attachment one and copy a range, then go to my transaction file and paste. Back to email two, the same thing. Then to email three same thing. I want to be able to copy (Add) from one, copy(Add) from two, copy(Add) from three, and finally paste int...

WTF happened to printing spots a multiple angles
Microsoft must have retarded monkeys designing their software. I upgraded to Publisher 2002 because of the amount of clients I had that were sending my 02' files. I was completely floored when I found that I can't send multiple spot colors at different angles to my imagesetter. Why would Microsoft say they have the most "printer friendly" software and then remove multiple screen angles? It's not like they have never added a way to do this in any previous version, they actually removed it from this upgrade. It's not a bug of any kind, Microsoft stated that the only wa...

Multiple recipient policies on same group
Hello, I am trying to have 2 mailbox manager policies on a single group. The first one moves messages to the System Cleanup Folder after 30 days and the next one deletes the messages after it has been in the System Cleanup Folder after 10 days. The second policy doesn't appear to be working. On the MS KB article for doing this, it says "Another common issue occurs when policies do not apply as you expect. This can be caused by overlapping policies. Only one mailbox recipient policy can be applied to each user. If you have more than one recipient policy applied to a user, make...

OT...RAW image support for Windows XP...OT
Microsoft RAW Image Thumbnailer and Viewer for Windows XP http://tinyurl.com/c2vf8 Whitepaper: Viewing and Organizing RAW Images in Windows XP http://tinyurl.com/cwpq5 -- John Inzer John, I read in the Serif forum today that the latest version of PhotoPlus can now convert RAW images. I presume it will also run under Win 98. Mike John Inzer wrote: > Microsoft RAW Image Thumbnailer > and Viewer for Windows XP > http://tinyurl.com/c2vf8 > > Whitepaper: Viewing and Organizing > RAW Images in Windows XP > http://tinyurl.com/cwpq5 > Thanks for the info. And acco...

Support? What Support?
I sent in a ticket two days ago and got no response out of anybody from Microsoft. My company pays dearly for software assurance. I don't have two days to wait for assistance or even for a response from Microsoft in order to get an issue resolved. I have had a sales department that has been screaming at me for two days to get a problem fixed. All I have gotten was lip service from the dispatcher that we will have a technician call you. Very poor customer service! My management has stated their discontentment with CRM and the number of problems this application has caused. ...

Does POS 2.0 support price-embedded barcodes?
Does anyone know if Microsoft Point of Sale 2.0 supports price-embedded barcodes (also known as random weight barcodes)? I have Digi scales that print out 12-digit barcodes with UPC and price info. I would like to implement POS and not RMS because it is much less complex. Thanks for any info. POS 2.0 does not support price-embedded barcodes. "Martin" wrote: > Does anyone know if Microsoft Point of Sale 2.0 supports price-embedded > barcodes (also known as random weight barcodes)? > > I have Digi scales that print out 12-digit barcodes with UPC and price info. &...

Support for my bank?
How can I request to have my banks online services added to the supported services for MS Money 2004? My bank offers transaction downloads in quicken, money, or csv format. I would prefer to not post my bank name on this newsgroup... if there is a site where I can submit the request, that would be best. -Shaun In microsoft.public.money, Bonnie Synhorst - MVP wrote: >Your bank needs to take the steps to become a certified provider. You need >to call them directly and request that they offer these services. But, of >course, whether they do it or not is up to them. > >&...

Passing the selection from a listbox to a querie
Hi, I'm simply trying to use a listbox to select a date and then punch a button to run a querie based on the selected date. The format of the link in the querie to the listbox is [forms]![Main Menu]![list_box_mnth_sel]![Mnth of Dump] where "Main Menu" is the name of the form containing the listbox and button and "list_box_mnth_sel" is the name of the listbox object and "Mnth of Dump" is the field title of the querie behind the listbox The listbox populates the date correctly when I open the form and when I manually put the date into the querie that I w...

Unable to get the window handle ... Windowless ActiveX controls are not supported
Hello, This exception : System.InvalidOperationException was caught Message="Unable to get the window handle for the 'AxMOSServer' control. Windowless ActiveX controls are not supported." Source="System.Windows.Forms" StackTrace: at System.Windows.Forms.AxHost.EnsureWindowPresent() at System.Windows.Forms.AxHost.InPlaceActivate() at System.Windows.Forms.AxHost.TransitionUpTo(Int32 state) at System.Windows.Forms.AxHost.CreateHandle() at System.Windows.Forms.Control.CreateControl(Boolean fIgnoreVisible) ...

Change merge button to "center across selection"
I can't find a way to assign the "center across selection" action to the "merge" button in excel. Modify and customize didn't help. Any ideas? Thanks for any help! BH try assigning a custom button to this code in your personal.xls Sub CenterAcross() Selection.HorizontalAlignment = xlCenterAcrossSelection End Sub -- Don Guillett SalesAid Software donaldb@281.com "Brian H" <brian.hamilton@smhco.com> wrote in message news:OuDPrqozFHA.2072@TK2MSFTNGP14.phx.gbl... > I can't find a way to assign the "center across selection" ac...

RMS Shopping Cart with Matrix Item Support
Web Integrator 2.3 Update: New West Technologies has released their latest version of the Web Integrator - version 2.3. Which is now also compatible with Kosmos Central's Web Service for X-Cart. Great New Benefits in Version 2.3: Supports Matrix Items - including separate detailed matrix images Microsoft Headquarters (HQ) Support Ability to pull inventory from a centralized HQ server while downloading orders to one specific store for shipping. Contact us today to see if your eCommerce solution is compatible to receive this Web Integrator update. Installation of this new version is reco...

is Turkish proof supported by office 2008?
Version: 2008 Operating System: Mac OS X 10.6 (Snow Leopard) Processor: Intel Email Client: pop hi, <br> I've tasted office 2008 in my mac and it is powerful. But, as being an editor, I really really need Turkish proofing support but as I can see I think there is no any support for that.(At least I couldn't find any in my trail version) <br><br>I had sent a feedback about that but I wanted to know any information about this issue. will MS support it or not? if so, when. Or maybe full version support it? If it is possible to know I will be glad. <br><br...