c# WinForm 中 treeview实现整行选择

nmgxgz 2009-04-28 01:14:29
如题
...全文
471 17 打赏 收藏 转发到动态 举报
写回复
用AI写文章
17 条回复
切换为时间正序
请发表友善的回复…
发表回复
nmgxgz 2009-05-06
  • 打赏
  • 举报
回复
谢谢“秋枫”,问题已解决
marvelstack 2009-04-29
  • 打赏
  • 举报
回复
设置TreeView.FullRowSelect 属性为true。如果选择突出显示跨越树视图控件的整个宽度,则为 true;否则为 false。默认为 false。
注意:
当 FullRowSelect 为 true 时,选择突出显示将跨越树视图的整个宽度,即整个显示区域的宽度而不仅仅是树节点标签的宽度。如果 ShowLines 设置为 true,则将忽略 FullRowSelect 属性。

下面的代码示例演示一个自定义的 TreeView。通过继承 TreeView 类,此自定义版本具有典型 TreeView 的所有功能。在构造函数中更改不同的属性值可以提供独特的外观。由于 ShowPlusMinus 属性设置为 false,因此该自定义控件还重写 OnAfterSelect 方法,以便单击节点时能够展开和折叠它们。

以这种方式自定义的控件可以在整个单位中使用,因此很容易提供一致的界面,而不需要在每个单独的项目中指定控件属性。


public class CustomizedTreeView : TreeView
{
public CustomizedTreeView()
{
// Customize the TreeView control by setting various properties.
BackColor = System.Drawing.Color.CadetBlue;
FullRowSelect = true;
HotTracking = true;
Indent = 34;
ShowPlusMinus = false;

// The ShowLines property must be false for the FullRowSelect
// property to work.
ShowLines = false;
}

protected override void OnAfterSelect(TreeViewEventArgs e)
{
// Confirm that the user initiated the selection.
// This prevents the first node from expanding when it is
// automatically selected during the initialization of
// the TreeView control.
if (e.Action != TreeViewAction.Unknown)
{
if (e.Node.IsExpanded)
{
e.Node.Collapse();
}
else
{
e.Node.Expand();
}
}

// Remove the selection. This allows the same node to be
// clicked twice in succession to toggle the expansion state.
SelectedNode = null;
}
}


fdc123 2009-04-28
  • 打赏
  • 举报
回复
真是搞不懂你说的是什么意思,难道是选择一个节点也选取了它的子节点么?
nmgxgz 2009-04-28
  • 打赏
  • 举报
回复
我只是说其中整行选择的效果,注意认真看帖,不要误导
LoveLife_Go 2009-04-28
  • 打赏
  • 举报
回复
dataGridView1.SelectionMode = DataGridViewSelectionMode.FullRowSelect;
LoveLife_Go 2009-04-28
  • 打赏
  • 举报
回复
这不是treeview
是DataGridView
nmgxgz 2009-04-28
  • 打赏
  • 举报
回复

如这个图的NO2
nmgxgz 2009-04-28
  • 打赏
  • 举报
回复
恩?
zgke 2009-04-28
  • 打赏
  • 举报
回复
正行..是选择蓝色的边框为宽和TreeView一样宽吗?
nmgxgz 2009-04-28
  • 打赏
  • 举报
回复
是吗,那listview可以吧?
JonasFeng 2009-04-28
  • 打赏
  • 举报
回复
楼主的意思是treeview 选择整个节点下的数据?

貌似好像没有整行的选择这一说法。
xiangbupingfan 2009-04-28
  • 打赏
  • 举报
回复
共同学习,顶上
wjf8882300 2009-04-28
  • 打赏
  • 举报
回复
treeview是单结点的,不知道你的整行选择所谓何意?
nmgxgz 2009-04-28
  • 打赏
  • 举报
回复
恩,不能吗
walkghost 2009-04-28
  • 打赏
  • 举报
回复
不懂你的意思。
ericzhangbo1982111 2009-04-28
  • 打赏
  • 举报
回复
。。。。你说的是treeview
不是listview
david_anwei 2009-04-28
  • 打赏
  • 举报
回复
treeview实现整行选择 ?

110,567

社区成员

发帖
与我相关
我的任务
社区描述
.NET技术 C#
社区管理员
  • C#
  • Web++
  • by_封爱
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告

让您成为最强悍的C#开发者

试试用AI创作助手写篇文章吧