473,836 Members | 1,455 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

TreeView multiple selections

Hi,

Is there a way for TreeView to have multiple selections? But I am not
talking about its checked boxes.

I want a way similar to ListView with MultiSelect = True. So I can use
[Ctrl] or [Shift] key and click to make multiple selections. Then when I
simply click one item, all previous selections are gone.

Thanks in advance.

Li

Oct 1 '07 #1
18 15385
Hi Li,

Yes, the .Net TreeView control does not support multiple selection by
default. We normally enable checkbox for all the TreeNodes, so that we may
use CheckBox to indicate the multiple selection. However, if you really
wanted to get the true multiple selection function in TreeView, you have to
customize TreeView control. The articles below provide the extended version
of TreeView with multiple selection function:
"C# TreeView with multiple selection"
http://www.codeproject.com/cs/miscctrl/treeviewms.asp
"Multi-Select TreeView"
http://windowsclient.net/downloads/f...entry1273.aspx
"Multi-Select TreeView Control in C#"
http://www.codeproject.com/cs/miscctrl/mwcontrols.asp

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 2 '07 #2
Hi Li,

Have you reviewed my reply to you? Does it make sense to you? If you still
need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 5 '07 #3
Hi, Jeffrey:

Thanks a lot for the help!
I have read your response but haven't got a chance to read the articles and
try them out. I will do that after I finish my current work.

Thanks again.

Li

""Jeffrey Tan[MSFT]"" wrote:
Hi Li,

Have you reviewed my reply to you? Does it make sense to you? If you still
need any help, please feel free to feedback, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 5 '07 #4
Hi Li,

Thank you for the confirmation.

Ok, if you need any further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 8 '07 #5
Hi, Jeffrey:

Now I am testing the first article: "C# TreeView with multiple selection".
The codes look ok. But I encounter a problem from TreeView.

After I click to select a node, then I click it again, it will not trigger
OnBeforeSelect or OnAfterSelect.
But if I click other nodes, i.e., not the last selected node, both of them
will be triggered.

Is TreeView designed by this way? If so, how to workaround to catch
selecting twice the node while pressing CTRL to un-select it?

By the way, I am using VB.net, not C#. But I think here is a raising event
issue.

Thanks in advance.

Li

""Jeffrey Tan[MSFT]"" wrote:
Hi Li,

Thank you for the confirmation.

Ok, if you need any further help, please feel free to post, thanks.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 12 '07 #6
Hi Li,

Thanks for your feedback.

Yes, this behavior also occurs in build-in TreeView control and is by
design. To workaround this behavior, you may handle the TreeView.Click
event. In this event, you may use check the mouse position to determine
which node is clicked. The code below demonstrates this logic:

Private Sub TreeView1_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TreeView1.Click
Dim pt As Point = Me.TreeView1.Po intToClient(New
Point(Control.M ousePosition.X, Control.MousePo sition.Y))
Dim tn As TreeNode = Me.TreeView1.Ge tNodeAt(pt)
If Not (tn Is Nothing) Then
'Perform your logic based on the clicked node
End If
End Sub

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 15 '07 #7
Thanks!

""Jeffrey Tan[MSFT]"" wrote:
Hi Li,

Thanks for your feedback.

Yes, this behavior also occurs in build-in TreeView control and is by
design. To workaround this behavior, you may handle the TreeView.Click
event. In this event, you may use check the mouse position to determine
which node is clicked. The code below demonstrates this logic:

Private Sub TreeView1_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TreeView1.Click
Dim pt As Point = Me.TreeView1.Po intToClient(New
Point(Control.M ousePosition.X, Control.MousePo sition.Y))
Dim tn As TreeNode = Me.TreeView1.Ge tNodeAt(pt)
If Not (tn Is Nothing) Then
'Perform your logic based on the clicked node
End If
End Sub

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 15 '07 #8
Hi, Jeffrey:

Look like for TreeView, if I click a node (selected), I can't set its
BackColor or ForeColor in codes. It is always painted as Highlighted.

Is it by designed? If so, how can I re-paint it to normal when selecting
twice with [CTRL]?

I suspect Microsoft has made changes to TreeView so 2005 version is
different from older version (2002) the article's codes run on.

Thanks.

Li

""Jeffrey Tan[MSFT]"" wrote:
Hi Li,

Thanks for your feedback.

Yes, this behavior also occurs in build-in TreeView control and is by
design. To workaround this behavior, you may handle the TreeView.Click
event. In this event, you may use check the mouse position to determine
which node is clicked. The code below demonstrates this logic:

Private Sub TreeView1_Click (ByVal sender As System.Object, ByVal e As
System.EventArg s) Handles TreeView1.Click
Dim pt As Point = Me.TreeView1.Po intToClient(New
Point(Control.M ousePosition.X, Control.MousePo sition.Y))
Dim tn As TreeNode = Me.TreeView1.Ge tNodeAt(pt)
If Not (tn Is Nothing) Then
'Perform your logic based on the clicked node
End If
End Sub

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 16 '07 #9
Hi Li,

Thanks for your feedback.

Yes, .Net TreeView control encapsulates Win32 native tree view control. All
these behaviors are by design by the win32 tree view control.

To customize the hightlighted node colors, we may use custom-draw to get it
done. Fortunately, .Net2.0 has added the build-in support for custom-draw.

To use custom draw for your task, you may set TreeView.DrawMo de to
OwnerDrawText and handle TreeView.DrawNo de event. Then, in this event, you
may check the status of each node and paints its text and background
rectangle based on your requirement. The code snippet demonstrates this
logic:

Private tagFont As New Font("Helvetica ", 8, FontStyle.Bold)

Private Sub TreeView1_DrawN ode(ByVal sender As System.Object, ByVal e
As System.Windows. Forms.DrawTreeN odeEventArgs) Handles TreeView1.DrawN ode
' Draw the background and node text for a selected node.
If (e.State And TreeNodeStates. Selected) <0 Then

' Draw the background of the selected node. The NodeBounds
' method makes the highlight rectangle large enough to
' include the text of a node tag, if one is present.
e.Graphics.Fill Rectangle(Brush es.Green, NodeBounds(e.No de))

' Retrieve the node font. If the node font has not been set,
' use the TreeView font.
Dim nodeFont As Font = e.Node.NodeFont
If nodeFont Is Nothing Then
nodeFont = CType(sender, TreeView).Font
End If

' Draw the node text.
e.Graphics.Draw String(e.Node.T ext, nodeFont, Brushes.White, _
e.Bounds.Left - 2, e.Bounds.Top)

' Use the default background and node text.
Else
e.DrawDefault = True
End If

' If a node tag is present, draw its string representation
' to the right of the label text.
If (e.Node.Tag IsNot Nothing) Then
e.Graphics.Draw String(e.Node.T ag.ToString(), tagFont, _
Brushes.Yellow, e.Bounds.Right + 2, e.Bounds.Top)
End If

' If the node has focus, draw the focus rectangle large, making
' it large enough to include the text of the node tag, if present.
If (e.State And TreeNodeStates. Focused) <0 Then
Dim focusPen As New Pen(Color.Black )
Try
focusPen.DashSt yle = System.Drawing. Drawing2D.DashS tyle.Dot
Dim focusBounds As Rectangle = NodeBounds(e.No de)
focusBounds.Siz e = New Size(focusBound s.Width - 1, _
focusBounds.Hei ght - 1)
e.Graphics.Draw Rectangle(focus Pen, focusBounds)
Finally
focusPen.Dispos e()
End Try
End If
End Sub

Private Function NodeBounds(ByVa l node As TreeNode) As Rectangle

' Set the return value to the normal node bounds.
Dim bounds As Rectangle = node.Bounds
If (node.Tag IsNot Nothing) Then

' Retrieve a Graphics object from the TreeView handle
' and use it to calculate the display width of the tag.
Dim g As Graphics = Me.TreeView1.Cr eateGraphics()
Dim tagWidth As Integer = CInt(g.MeasureS tring( _
node.Tag.ToStri ng(), tagFont).Width) + 6

' Adjust the node bounds using the calculated value.
bounds.Offset(t agWidth \ 2, 0)
bounds = Rectangle.Infla te(bounds, tagWidth \ 2, 0)
g.Dispose()
End If
Return bounds
End Function 'NodeBounds

Hope this helps.

Best regards,
Jeffrey Tan
Microsoft Online Community Support
=============== =============== =============== =====
Get notification to my posts through email? Please refer to
http://msdn.microsoft.com/subscripti...ult.aspx#notif
ications.

Note: The MSDN Managed Newsgroup support offering is for non-urgent issues
where an initial response from the community or a Microsoft Support
Engineer within 1 business day is acceptable. Please note that each follow
up response may take approximately 2 business days as the support
professional working with you may need further investigation to reach the
most efficient resolution. The offering is not appropriate for situations
that require urgent, real-time or phone-based interactions or complex
project analysis and dump analysis issues. Issues of this nature are best
handled working with a dedicated Microsoft Support Engineer by contacting
Microsoft Customer Support Services (CSS) at
http://msdn.microsoft.com/subscripti...t/default.aspx.
=============== =============== =============== =====
This posting is provided "AS IS" with no warranties, and confers no rights.

Oct 17 '07 #10

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

1
3564
by: theoryboy | last post by:
I'm trying to implement multiple selection functionality in a Tix Hlist using a control-click. I've bound control-click to a function that uses selection_set to add to the selection, but it doesn't seem to work. Only the last clicked item appears selected (highlighted) in the display and the return from info_selection only ever contains the last 2 items, rather than all the items I have control-clicked. It's odd, because if I set up the...
1
3092
by: jeffgeorge | last post by:
Trying to create multiple acct reports based on the selection in a list box. I've set the list box for multiple selections, and in the report data source, I have a SQL statement which is reading the list box(when there is a single selection) but no luck with multiple selections. I'm suspecting I need to write a bit of code using an array. Does anyone have any insight or direction on how I might add?
2
2105
by: Craig B. | last post by:
I am relativly new to access 2000 and am having some trouble with a report. I am not sure what I want to do is something I can do in access. I want to be able to choose from a combo box multiple selections in a form and from those selections present them in a report. For example select a selection A,B, and C out of 9 possible choices. Then show them seperated by a comma in a field in the report. I also want the option of only selecting...
1
1318
by: Andrew | last post by:
Hi, friends, Is there a way to make a TreeView allow multiple selections, like in a List control? Thanks.
2
1607
by: Steffen Loringer | last post by:
Hi all, may be an easy question: How can I allow multiple selections in a dropdownlist? Thanks Steffen
1
1993
by: Yvonne | last post by:
We have a Contacts database which categorises our Contacts by three categories eg Country, Language and Skills. It has a combo box ( not bound) which is populated from a union query that gets its values from the 3 category fields. At present the after-update event on the combo box generates a report which selects those contacts matching the combo selection. Now, as you might have guessed, I want to get a report which is based on...
4
2873
by: tbayse | last post by:
Hello, I have a question about making multiple selection queries in Access. I am running windows XP and Access 2003. Up until this point I had a form where a user would make single selections from a combo box and the following combo box would filter based on the initial selection. I now would like to give the opportunity to make multiple selections and the following combo box would filter based on that. How do I go about declaring this...
0
1402
by: Gunnar Hurtig | last post by:
Hi All I am relatively new to Tkinter and am putting a wraparound to the ATNF ASAP program. In one part I present several long lists in list boxes for selection. My code will remember the multiple selections made but I woul also like to highlight and maintain the highlighted items as I make additional selections. I can maintain the highlighted selections from listbox to listbox, but can't seem to figure out how to maintain the selected...
0
3170
by: Germaris | last post by:
Hi there! Is it possible to make multiple selections in a ComboBox ? i.e. make n consecutive selections and store them in an array or make n selections in the open list of the CB by using (for example) the click-Shift Key keystroke Purpose is to allow the user to select multiple different issues of a magazine with a maximum ease of use... (Code I use is attached below) Many thanks for your help!
0
10558
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven tapestry of website design and digital marketing. It's not merely about having a website; it's about crafting an immersive digital experience that captivates audiences and drives business growth. The Art of Business Website Design Your website is...
0
10257
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
0
9387
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing, and deployment—without human intervention. Imagine an AI that can take a project description, break it down, write the code, debug it, and then launch it, all on its own.... Now, this would greatly impact the work of software developers. The idea...
1
7794
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6981
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
5651
by: TSSRALBI | last post by:
Hello I'm a network technician in training and I need your help. I am currently learning how to create and manage the different types of VPNs and I have a question about LAN-to-LAN VPNs. The last exercise I practiced was to create a LAN-to-LAN VPN between two Pfsense firewalls, by using IPSEC protocols. I succeeded, with both firewalls in the same network. But I'm wondering if it's possible to do the same thing, with 2 Pfsense firewalls...
1
4459
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
2
4022
muto222
by: muto222 | last post by:
How can i add a mobile payment intergratation into php mysql website.
3
3116
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.