Generic List - moving an item within the list

前端 未结 10 727
后悔当初
后悔当初 2020-11-28 04:32

So I have a generic list, and an oldIndex and a newIndex value.

I want to move the item at oldIndex, to newIndex.

10条回答
  •  无人及你
    2020-11-28 05:09

    Is more simple guys just do this

        public void MoveUp(object item,List Concepts){
    
            int ind = Concepts.IndexOf(item.ToString());
    
            if (ind != 0)
            {
                Concepts.RemoveAt(ind);
                Concepts.Insert(ind-1,item.ToString());
                obtenernombres();
                NotifyPropertyChanged("Concepts");
            }}
    

    Do the same with MoveDown but change the if for "if (ind !=Concepts.Count())" and the Concepts.Insert(ind+1,item.ToString());

提交回复
热议问题