首页
学习
活动
专区
圈层
工具
发布
首页
学习
活动
专区
圈层
工具
MCP广场
社区首页 >问答首页 >WPF -实现允许项目上下移动的列表框

WPF -实现允许项目上下移动的列表框
EN

Stack Overflow用户
提问于 2009-01-11 06:27:05
回答 7查看 6.4K关注 0票数 2

这与我上一篇文章有关。

我想在列表框项目上有向上和向下按钮,这样他们就可以向上/向下移动,即改变了它在列表中的索引。

你知道我该怎么做吗?

马尔科姆

EN

Stack Overflow用户

发布于 2011-08-30 13:02:00

向上移动

代码语言:javascript
运行
复制
int index = listbox.SelectedIndex;
if (index != -1)
{
    if (index > 0)
    {
        ListBoxItem lbi = (ListBoxItem)listbox.Items[index];
        listbox.Items.RemoveAt(index);
        index--;
        listbox.Items.Insert(index, lbi);
        listbox.SelectedIndex = index;
        listbox.ScrollIntoView(lbi);
    }
}

下移

代码语言:javascript
运行
复制
int index = listbox.SelectedIndex;
if (index != -1)
{
    if (index < listbox.Items.Count - 1)
    {
        listboxlbi = (ListBoxItem)listbox.Items[index];
        listbox.Items.RemoveAt(index);
        index++;
        listbox.Items.Insert(index, lbi);
        listbox.SelectedIndex = index;
        listbox.ScrollIntoView(lbi);
    }
}
票数 1
EN
查看全部 7 条回答
页面原文内容由Stack Overflow提供。腾讯云小微IT领域专用引擎提供翻译支持
原文链接:

https://stackoverflow.com/questions/432462

复制
相关文章

相似问题

领券
问题归档专栏文章快讯文章归档关键词归档开发者手册归档开发者手册 Section 归档