Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. WCF and WF
  4. Moving Listview Item up or down

Moving Listview Item up or down

Scheduled Pinned Locked Moved WCF and WF
wpftutorialquestionwcfcom
2 Posts 1 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • S Offline
    S Offline
    Sevententh
    wrote on last edited by
    #1

    Hi I'm trying to find how to move a listview item up or down (using MVVM) in the collection and to change the data bound field. The problem is not the selected item Order being changed but the item that it's moved in front or behind being changed. A simple example

    <UserControl x:Class="Views.TestPage"
    xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

    <DockPanel >
        <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
            <Button Content="Up" Command="{Binding Path=UpCommand}" />
            <Button Content="Down" Command="{Binding Path=DownCommand}" />
        </StackPanel>
        <ListView ItemsSource="{Binding Path=CurrentList}" IsSynchronizedWithCurrentItem="True">
            <ListView.View>
                <GridView>
                    <GridViewColumn Header="Order" DisplayMemberBinding="{Binding Path=OrderPriority}"/>
                    <GridViewColumn Header="Question" DisplayMemberBinding="{Binding Path=Question}" />
                </GridView>
            </ListView.View>
        </ListView>
    </DockPanel>
    

    </UserControl>

    Model

    namespace Models
    {
    public class myTable
    {
    public Int32 OrderPriority { get; set; }
    public String Question { get; set; }
    }
    }

    I don't really want to bombard anybody with viewmodel code, but lets just say I have all the necessary bindings that are needed. When the user clicks the Up button it executes the following

        public void ExecuteUpCommand()
        {
            UpCommand.CommandSucceeded = false;
    
            //The collection is stored in myCollectionView
            //The selected ListViewItem is stored as CurrentItem (of type myTable), 
            //retrieved through myCollectionView\_CurrentChanged
    
            //Do I use myCollectionView.MoveCurrentToPrevious();
    

    //Update current item with new Order number serviceClient.UpdateMyTable(CurrentItem)
    //Update the replaced item serviceClient.UpdateMyTable()??

            UpCommand.CommandSucceeded = true;
        }
    

    What do I do here?

    S 1 Reply Last reply
    0
    • S Sevententh

      Hi I'm trying to find how to move a listview item up or down (using MVVM) in the collection and to change the data bound field. The problem is not the selected item Order being changed but the item that it's moved in front or behind being changed. A simple example

      <UserControl x:Class="Views.TestPage"
      xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
      xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml">

      <DockPanel >
          <StackPanel Orientation="Horizontal" DockPanel.Dock="Top">
              <Button Content="Up" Command="{Binding Path=UpCommand}" />
              <Button Content="Down" Command="{Binding Path=DownCommand}" />
          </StackPanel>
          <ListView ItemsSource="{Binding Path=CurrentList}" IsSynchronizedWithCurrentItem="True">
              <ListView.View>
                  <GridView>
                      <GridViewColumn Header="Order" DisplayMemberBinding="{Binding Path=OrderPriority}"/>
                      <GridViewColumn Header="Question" DisplayMemberBinding="{Binding Path=Question}" />
                  </GridView>
              </ListView.View>
          </ListView>
      </DockPanel>
      

      </UserControl>

      Model

      namespace Models
      {
      public class myTable
      {
      public Int32 OrderPriority { get; set; }
      public String Question { get; set; }
      }
      }

      I don't really want to bombard anybody with viewmodel code, but lets just say I have all the necessary bindings that are needed. When the user clicks the Up button it executes the following

          public void ExecuteUpCommand()
          {
              UpCommand.CommandSucceeded = false;
      
              //The collection is stored in myCollectionView
              //The selected ListViewItem is stored as CurrentItem (of type myTable), 
              //retrieved through myCollectionView\_CurrentChanged
      
              //Do I use myCollectionView.MoveCurrentToPrevious();
      

      //Update current item with new Order number serviceClient.UpdateMyTable(CurrentItem)
      //Update the replaced item serviceClient.UpdateMyTable()??

              UpCommand.CommandSucceeded = true;
          }
      

      What do I do here?

      S Offline
      S Offline
      Sevententh
      wrote on last edited by
      #2

      I think I've found the answer but if you can think of a better way please let me know

      Int32 currentPosition = myCollectionView.CurrentPosition;
      if (currentPosition > 0)
      {
      CurrentItem.OrderPriority = currentPosition;

      myCollectionView.MoveCurrentToPrevious();
      CurrentItem.OrderPriority = CurrentItem.OrderPriority + 1;
      

      }

      myCollectionView.Refresh();

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups