在我的 c# windows 应用程序中,我有一个复选框设置为 true 的树视图列表框。在运行时,我的程序在 xml 文件中检查此树视图的节点。在我的应用程序中,我使用下面显示的代码隐藏了父节点复选框:
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;
[DllImport("user32.dll")]
static extern IntPtr SendMessage(IntPtr hWnd, uint Msg, IntPtr wParam,
IntPtr lParam);
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;
}
void tree_DrawNode(object sender, DrawTreeNodeEventArgs e)
{
if (e.Node.Level == 1)
HideCheckBox(e.Node.Parent);
e.DrawDefault = true;
}
private void HideCheckBox(TreeNode node)
{
TVITEM tvi = new TVITEM();
tvi.hItem = node.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.taskslctor_treeview.Handle, TVM_SETITEM, IntPtr.Zero, lparam);
}
我现在想要的是我应该能够检查任何选择的子节点(在运行时),如果有任何选择,我应该能够将所选子节点的文本添加到数组列表中(因为可以选择多个复选框)和如果未选择消息框显示为未选择。
在隐藏父复选框之前,当我尝试下面的代码时,它工作正常..但是现在(隐藏父复选框后)这不起作用..
public void checkednodes()
{
foreach (TreeNode node in taskslctor_treeview.Nodes)
{
if (node.Checked)
{
check.Add(node.Text);
MessageBox.Show(check.ToString());
}
}
if (check.Count == 0)
{
MessageBox.Show("Atleast one task needs to be selected!!", "Error");
}
}
任何立即的帮助将不胜感激......因为我的工作现在被搁置了......