如何将项目的列表框上下?如何将、上下、项目、列表

2023-09-02 23:51:33 作者:百分百无添加纯可爱

我有一个listBox1中的对象,它包含了一些项目。我有一个按钮,将选定的项,另一个向下移动选定的项目。我应该在code是两个按钮?

解决方案

 私人无效UpClick()
{
    //仅当第一个项目是不是当前
    如果(listBox1.ListIndex大于0)
    {
        //添加重复的项目在列表框中
        listBox1.AddItem(listBox1.Text,listBox1.ListIndex  -  1);
        //使其成为当前项目
        listBox1.ListIndex =(listBox1.ListIndex  -  2);
        //删除旧的发生这一项目
        listBox1.RemoveItem(listBox1.ListIndex + 2);
    }
}

私人无效DownClick()
{
   //只有在最后一个项目是不是当前
   如果(!(listBox1.ListIndex = -1)及及(listBox1.ListIndex&所述; listBox1.ListCount  -  1))
   {
      //在列表框下添加重复项
      listBox1.AddItem(listBox1.Text,listBox1.ListIndex + 2);
      //使其成为当前项目
      listBox1.ListIndex = listBox1.ListIndex + 2;
      //删除旧的发生这一项目
      listBox1.RemoveItem(listBox1.ListIndex  -  2);
   }
}
 

I have a listBox1 object and it contains some items. I have a button to move selected item up and another to move selected item down. What should the code be to the two buttons?

解决方案 易语言列表框的某个内容怎么上下移动

private void UpClick()
{
    // only if the first item isn't the current one
    if(listBox1.ListIndex > 0)
    {
        // add a duplicate item up in the listbox
        listBox1.AddItem(listBox1.Text, listBox1.ListIndex - 1);
        // make it the current item
        listBox1.ListIndex = (listBox1.ListIndex - 2);
        // delete the old occurrence of this item
        listBox1.RemoveItem(listBox1.ListIndex + 2);
    }
}

private void DownClick()
{
   // only if the last item isn't the current one
   if((listBox1.ListIndex != -1) && (listBox1.ListIndex < listBox1.ListCount - 1))
   {
      // add a duplicate item down in the listbox
      listBox1.AddItem(listBox1.Text, listBox1.ListIndex + 2);
      // make it the current item
      listBox1.ListIndex = listBox1.ListIndex + 2;
      // delete the old occurrence of this item
      listBox1.RemoveItem(listBox1.ListIndex - 2);
   }
}