Google Groups no longer supports new Usenet posts or subscriptions. Historical content remains viewable.
Dismiss

TreeView - Only Some Checkboxes

1,937 views
Skip to first unread message

Phil Jones

unread,
Nov 11, 2004, 12:31:49 AM11/11/04
to
The the [TreeView] I'm wondering if there is a way to set certain nodes with
a check-box, and leave other without one.

I can't see a way to do this. Setting "Checkboxes" to True seems to be all
or nothing....and I can't see a property on the TreeNode object (which seems
like the place this option should be).

Thank everyone!!


Claes Bergefall

unread,
Nov 11, 2004, 3:13:50 AM11/11/04
to
Take a look here:
http://groups.google.se/groups?as_umsgid=%231UvA2K...@TK2MSFTNGP10.phx.gbl&lr=&hl=sv

/claes

"Phil Jones" <phil_ne...@hotmail.com> wrote in message
news:u3uCs46x...@TK2MSFTNGP12.phx.gbl...

Jeffrey Tan[MSFT]

unread,
Nov 11, 2004, 3:54:10 AM11/11/04
to
Hi Phil,

Based on my understanding, you want to exclude some checkboxes from several
treenodes in treeview.

Currently, there is not build-in support to get this done. But we can send
a TVM_SETITEM message to the treeview control, set TVITEM structure's state
field to 0, and TVITEM's hItem field to the treenode's handle. Then this
treenode will be got rid of the checkbox.

Sample code lists below:

public const int TVIF_STATE = 0x8;
public const int TVIS_STATEIMAGEMASK = 0xF000;
public const int TV_FIRST= 0x1100;
public const int TVM_SETITEM = TV_FIRST + 63;

public struct TVITEM
{
public int mask;
public IntPtr hItem;
public int state;
public int stateMask;
[MarshalAs(UnmanagedType.LPTStr)]
public String lpszText;
public int cchTextMax;
public int iImage;
public int iSelectedImage;
public int cChildren;
public IntPtr lParam;
}

[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);

private void button1_Click(object sender, System.EventArgs e)
{
TVITEM tvi=new TVITEM();
tvi.hItem=this.treeView1.SelectedNode.Handle;
tvi.mask=TVIF_STATE;
tvi.stateMask = TVIS_STATEIMAGEMASK;
tvi.state=0;
IntPtr lparam=Marshal.AllocHGlobal(Marshal.SizeOf(tvi));
Marshal.StructureToPtr(tvi, lparam, false);
SendMessage(this.treeView1.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
}
This code hides the selected treenode's checkbox and it works well on my
side. You may copy and paste in your project to have a test.
=========================================================
Thank you for your patience and cooperation. If you have any questions or
concerns, please feel free to post it in the group. I am standing by to be
of assistance.

Best regards,
Jeffrey Tan
Microsoft Online Partner Support
Get Secure! - www.microsoft.com/security
This posting is provided "as is" with no warranties and confers no rights.

Phil Jones

unread,
Nov 12, 2004, 4:35:56 AM11/12/04
to
Brilliant Jeffrey,

Just got one little question. I've been converting your code to VB.NET, and
I'm getting a compilation error complaining that the TVM_SETITEM constant
cannot be converted to an unsigned integer.

In your code there was a note: "'ToDo: Unsigned Integers not supported"

Not sure what to do here. I haven't dont anything with unsigned Ints
before. Can I do a conversion somehow, and if so - where and how.

Many thanks for your efforts Jeffrey!

--
===
Phil
(Auckland | Aotearoa)


Phil Jones

unread,
Nov 12, 2004, 4:40:46 AM11/12/04
to
Cool - thanks Claes. I see that is a VB version of the code Jeffrey
supplied - which is good for me.

Jeffrey, please ignore my dopy queston about unsigned Ints :)

Cheers!

--
===
Phil Cockfield
(Auckland | Aotearoa)\


Jeffrey Tan[MSFT]

unread,
Nov 14, 2004, 9:00:49 PM11/14/04
to
Ok, if you need further help, please feel free to post, I will help you.

prabhaka...@gmail.com

unread,
Dec 11, 2013, 2:18:35 AM12/11/13
to
On Monday, November 15, 2004 7:30:49 AM UTC+5:30, "Jeffrey Tan[MSFT]" wrote:
> Ok, if you need further help, please feel free to post, I will help you.Best regards,Jeffrey TanMicrosoft Online Partner Support Get Secure! - www.microsoft.com/security This posting is provided "as is" with no warranties and confers no rights.

Hi jeffrey,

Thanks for Post. the Code Which you have given working fine.Awesome.

Really Great Work.

Message has been deleted
0 new messages