PC Review


Reply
Thread Tools Rating: Thread Rating: 1 votes, 5.00 average.

Treeview and Checkbox question

 
 
Elmo Watson
Guest
Posts: n/a
 
      27th Dec 2007

Is there any way to make checking a checkbox in a Treeview mutually
exclusive?

That is, to make it so that only one item may be selected....


 
Reply With Quote
 
 
 
 
Robbe Morris - [MVP] C#
Guest
Posts: n/a
 
      30th Dec 2007
You have to write your own code for that. If the current node
has just been checked, iterate through the tree and uncheck every
other node. If the current node is unchecked, do nothing.

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx



"Elmo Watson" <(E-Mail Removed)> wrote in message
news:%23$(E-Mail Removed)...
>
> Is there any way to make checking a checkbox in a Treeview mutually
> exclusive?
>
> That is, to make it so that only one item may be selected....
>
>


 
Reply With Quote
 
Elmo Watson
Guest
Posts: n/a
 
      31st Dec 2007
What Treeview event do I use for determining whether a checkbox has been
checked?


"Robbe Morris - [MVP] C#" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You have to write your own code for that. If the current node
> has just been checked, iterate through the tree and uncheck every
> other node. If the current node is unchecked, do nothing.
>
> --
> Robbe Morris [Microsoft MVP - Visual C#]
> .NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
> http://www.eggheadcafe.com/tutorials...oyment--m.aspx
>
>
>
> "Elmo Watson" <(E-Mail Removed)> wrote in message
> news:%23$(E-Mail Removed)...
>>
>> Is there any way to make checking a checkbox in a Treeview mutually
>> exclusive?
>>
>> That is, to make it so that only one item may be selected....
>>
>>

>



 
Reply With Quote
 
Elmo Watson
Guest
Posts: n/a
 
      31st Dec 2007
I've got this code:

If Treeview1.SelectedNode.Checked = True Then
For Each nd As TreeNode In Treeview1.Nodes
If nd.Text <> Treeview1.SelectedNode.Text Then
nd.Checked = False
End If
Next
End If
I've tried this in the NodeMouseClick event
but, when I click on the checkbox in the treeview, the node is not selected,
so I get the old
'object reference not set to an instance of an object'
error

I need to, when I check the node (I guess), have the node selected at the
same time - - am I right?

If so, how do I do that?



"Robbe Morris - [MVP] C#" <(E-Mail Removed)> wrote in message
news:(E-Mail Removed)...
> You have to write your own code for that. If the current node
> has just been checked, iterate through the tree and uncheck every
> other node. If the current node is unchecked, do nothing.
>
> --
> Robbe Morris [Microsoft MVP - Visual C#]
> .NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
> http://www.eggheadcafe.com/tutorials...oyment--m.aspx
>
>
>
> "Elmo Watson" <(E-Mail Removed)> wrote in message
> news:%23$(E-Mail Removed)...
>>
>> Is there any way to make checking a checkbox in a Treeview mutually
>> exclusive?
>>
>> That is, to make it so that only one item may be selected....
>>
>>

>



 
Reply With Quote
 
Robbe Morris - [MVP] C#
Guest
Posts: n/a
 
      31st Dec 2007
You've always got to check to see if .SelectedNode != null
first.

Here, download this

http://www.eggheadcafe.com/tutorials...faq--drag.aspx

It is a TreeView basics code sample that demonstrates some things you'll
need.

--
Robbe Morris [Microsoft MVP - Visual C#]
..NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
http://www.eggheadcafe.com/tutorials...oyment--m.aspx



"Elmo Watson" <(E-Mail Removed)> wrote in message
news:%(E-Mail Removed)...
> I've got this code:
>
> If Treeview1.SelectedNode.Checked = True Then
> For Each nd As TreeNode In Treeview1.Nodes
> If nd.Text <> Treeview1.SelectedNode.Text Then
> nd.Checked = False
> End If
> Next
> End If
> I've tried this in the NodeMouseClick event
> but, when I click on the checkbox in the treeview, the node is not
> selected, so I get the old
> 'object reference not set to an instance of an object'
> error
>
> I need to, when I check the node (I guess), have the node selected at the
> same time - - am I right?
>
> If so, how do I do that?
>
>
>
> "Robbe Morris - [MVP] C#" <(E-Mail Removed)> wrote in message
> news:(E-Mail Removed)...
>> You have to write your own code for that. If the current node
>> has just been checked, iterate through the tree and uncheck every
>> other node. If the current node is unchecked, do nothing.
>>
>> --
>> Robbe Morris [Microsoft MVP - Visual C#]
>> .NET Setup Deployment - MSI, Cassini, SQL Server, NTFS
>> http://www.eggheadcafe.com/tutorials...oyment--m.aspx
>>
>>
>>
>> "Elmo Watson" <(E-Mail Removed)> wrote in message
>> news:%23$(E-Mail Removed)...
>>>
>>> Is there any way to make checking a checkbox in a Treeview mutually
>>> exclusive?
>>>
>>> That is, to make it so that only one item may be selected....
>>>
>>>

>>

>
>


 
Reply With Quote
 
 
 
Reply

Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off
Trackbacks are On
Pingbacks are On
Refbacks are Off


Similar Threads
Thread Thread Starter Forum Replies Last Post
VGA Treeview and Checkbox JB Microsoft Dot NET Compact Framework 2 13th Aug 2007 09:45 AM
TreeView CheckBox Jalal Akram Microsoft Dot NET Framework Forms 0 16th Jul 2004 08:22 AM
TreeView Checkbox question Zac Maclean Microsoft VB .NET 0 9th Mar 2004 06:25 PM
TreeView CheckBox question Chung Microsoft Dot NET Compact Framework 4 16th Oct 2003 07:51 PM
How can I get the checkbox value in treeview. bearbaba Microsoft C# .NET 0 12th Jul 2003 07:58 AM


Features
 

Advertising
 

Newsgroups
 


All times are GMT +1. The time now is 12:01 AM.