树视图节点重选

发布于 2025-01-06 12:25:09 字数 1194 浏览 1 评论 0原文

我正在研究紧凑框架 2.0 并使用 c#。 我在树视图节点重新选择方面遇到问题。场景是这样的: 温度0 温度1 温度2 温度3 我在树视图中有一些节点,并使用向上和向下箭头来上下移动节点。 但问题是,一旦我选择一个节点并单击向上箭头,节点就会向上移动 我无法选择该节点正下方的节点。 假设我选择 temp3 并按向上箭头,则该 temp3 将被 temp2 替换。 像这样: 温度0 温度1 温度3 温度2 此后我无法选择 temp2,但可以选择 temp3 和其他节点(无论发生什么)。


我使用此代码作为向上箭头:

int paramPos = this.treeView1.SelectedNode.Index;

if (paramPos > 0)

{

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;

this.treeView1.Nodes[paramPos] = this.treeView1.Nodes[paramPos - 1];

this.treeView1.Nodes[paramPos - 1] = tempNode;

this.treeView1.SelectedNode = this.treeView1.Nodes[paramPos - 1];

foreach (System.Windows.Forms.TreeNode tnode in this.treeView1.Nodes)

{

ArgumentNumberInfo ai = (ArgumentNumberInfo)tnode.Tag;

ai.ArgNo = tnode.Index + 1;

}

                  treeView1.SelectedNode = tempNode;
                  this.treeView1_AfterSelect(null, null);


            }
        }

按向上箭头后,节点将向上,但我无法选择下面的节点。 Node0、

node1、

node2

、node3

如果您选择node3并单击向上箭头,node3将上升,node2将下降,但您无法选择node2。 请给我一些线索为什么会发生。 感谢您的宝贵时间。

I'm working on compact framework 2.0 and using c#.
I have problem with treeview node reselection. Scenario is like this :
temp0
temp1
temp2
temp3
I have some node in treeview and using up and down arrow for moving node up and down.
but problem is that once i select a node and clicking up arrow, node is moved up
and I cann't select node just below this node.
Suppose I select temp3 and press up arrow, this temp3 is replaced by temp2.
like this:
temp0
temp1
temp3
temp2
after this I cann't select temp2 but able to select temp3 and other node whatever is up.


I'm using this code for up arrow:

int paramPos = this.treeView1.SelectedNode.Index;

if (paramPos > 0)

{

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;

this.treeView1.Nodes[paramPos] = this.treeView1.Nodes[paramPos - 1];

this.treeView1.Nodes[paramPos - 1] = tempNode;

this.treeView1.SelectedNode = this.treeView1.Nodes[paramPos - 1];

foreach (System.Windows.Forms.TreeNode tnode in this.treeView1.Nodes)

{

ArgumentNumberInfo ai = (ArgumentNumberInfo)tnode.Tag;

ai.ArgNo = tnode.Index + 1;

}

                  treeView1.SelectedNode = tempNode;
                  this.treeView1_AfterSelect(null, null);


            }
        }

After pressing up arrow node is going to up but i cann't able to select node below this.
Node0

node1

node2

node3

If you select node3 and click on up arrow node3 will go up and node2 will come down but you cann't select node2.
please give me some clue why is it happening.
Thnx for your time.

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

瘫痪情歌 2025-01-13 12:25:09

Treeview 节点由内部链表维护。我认为您用来交换它们的方法使链接列表变得混乱。这是我引用的代码部分:

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;
this.treeView1.Nodes[paramPos] = this.treeView1.Nodes[paramPos - 1];
this.treeView1.Nodes[paramPos - 1] = tempNode;

尝试以下代码代替上面的代码:

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;
this.treeView1.Remove(tempNode);
this.treeView1.Insert(paramPos - 1, tempNode);

Treeview nodes are maintained by an internal linked list. I think the method that you're using to swap them around is confusing that linked list. Here's the part of the code that I'm referring to:

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;
this.treeView1.Nodes[paramPos] = this.treeView1.Nodes[paramPos - 1];
this.treeView1.Nodes[paramPos - 1] = tempNode;

Try the following in place of the code above:

System.Windows.Forms.TreeNode tempNode = this.treeView1.SelectedNode;
this.treeView1.Remove(tempNode);
this.treeView1.Insert(paramPos - 1, tempNode);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文