当前位置:编程学习 > C#/ASP.NET >>

如何将ListView控件选中的项向上移动或向下移动

如何将ListView控件选中的项向上移动或向下移动 C#
--------------------编程问答-------------------- 代码里重新设置他们的index. --------------------编程问答--------------------
引用 1 楼 whChina 的回复:
代码里重新设置他们的index.
--------------------编程问答-------------------- 写代码重新设置index! --------------------编程问答-------------------- 重新设置index! --------------------编程问答-------------------- //上移
private void pictureBox_upmove_Click(object sender, EventArgs e)
        {
      
            for(int i=0;i<this.myListView_look.SelectedItems.Count;i++)
            {
                System.Windows.Forms.ListViewItem listViewItem = this.myListView_look.SelectedItems[i];
                int index = this.myListView_look.SelectedItems[i].Index - 1;
                if (index < 0) return  ;
                this.myListView_look.Items.Remove(this.myListView_look.SelectedItems[i]);
                this.myListView_look.Items.Insert(index, listViewItem);
                listViewItem.Selected = true;
            }
        }

//下移
        private void pictureBox_downmove_Click(object sender, EventArgs e)
        {
            
            for (int i = this.myListView_look.SelectedItems.Count-1; i > -1; i--)
            {
                System.Windows.Forms.ListViewItem listViewItem = this.myListView_look.SelectedItems[i];
                int index = this.myListView_look.SelectedItems[i].Index + 1;
                if (index > this.myListView_look.Items.Count -1) return;
                this.myListView_look.Items.Remove(this.myListView_look.SelectedItems[i]);
                this.myListView_look.Items.Insert(index, listViewItem);
                listViewItem.Selected = true;
                
            }

        } --------------------编程问答-------------------- 楼主好问题啊,我也正需要这方面资料呢,谢谢,答案出来别人贴出来,大家学习啊 --------------------编程问答-------------------- 楼主好问题啊,我也正需要这方面资料呢,谢谢,答案出来别人贴出来,大家学习啊 --------------------编程问答--------------------
引用 5 楼 try530 的回复:
//上移 
private void pictureBox_upmove_Click(object sender, EventArgs e) 
        { 
      
            for(int i=0;i <this.myListView_look.SelectedItems.Count;i++) 
            { 
                System.Windows.Forms.ListViewItem listViewItem = this.myListView_look.SelectedItems[i]; 
                int index = this.myListView_look.SelectedItems[i].Index - 1; 
                if (index …

支持
补充:.NET技术 ,  其他语言
CopyRight © 2022 站长资源库 编程知识问答 zzzyk.com All Rights Reserved
部分文章来自网络,