-5

I am using a poco class for the following screen but im just wondering how I would achieve the move up and down elements of this screenenter image description here

I am using ObservableCollection to add my items to a mutual list my question is how would I achieve the move up and move down. I no I would need to change the poco class in real time but not sure how I would achieve this

   private void AddColumn(object sender, RoutedEventArgs e)
    {

        if (this.WizardData == null)
            return;

        if (this.WizardData.ConcreteCustomColumnsProxy == null)
            this.WizardData.ConcreteCustomColumnsProxy = new ObservableCollection<CustomColumnsModel>();

        this.WizardData.ConcreteCustomColumnsProxy.Add(new CustomColumnsModel() { CustomColumnsDisplayName = txtDsiplayName.Text
            , CustomColumnsOrder = 1, CustomColumnsWidth = Convert.ToInt32(txtWdith.Text) });

        this.listView1.ItemsSource = this.WizardData.ConcreteCustomColumnsProxy;
        this.listView1.UnselectAll();

        this.listView1.Items.Refresh();

My Poco class is as follows

 public event PropertyChangedEventHandler PropertyChanged;
    public const string IdPropertyName = "CustomColumnsID";
    private Guid _Id = Guid.Empty;
    public Guid CustomColumnsID
    {
        get { return _Id; }
        set
        {
            if (_Id == value)
                return;
            _Id = value;
            NotifyPropertyChanged(IdPropertyName);
        }
    }


    public string CustomColumnsDisplayName { get; set; }
    public int CustomColumnsWidth { get; set; }
    public int CustomColumnsOrder { get; set; }  


    protected void NotifyPropertyChanged(string key)
    {
        if (this.PropertyChanged != null)
        {
            this.PropertyChanged(this, new PropertyChangedEventArgs(key));
        }
    }

    public EnterpriseManagementObject ActualData { get; private set; }

}
c-sharp-and-swiftui-devni
  • 3,743
  • 4
  • 39
  • 100
  • 5
    This question and its two siblings are being discussed on Meta: http://meta.stackoverflow.com/questions/270904/what-is-going-on-with-these-3-questions-about-wpf-reorganising-lists?noredirect=1#comment91513_270904 @Fry: You may like to participate/view the discussion to learn more about how the site operates and how to product better questions. – Frames Catherine White Sep 08 '14 at 09:10

1 Answers1

4

You have some sort of DataGrid control. You need to data bind a collection property to the DataGrid.ItemsSource property and a property of the same type as the items in the collection to the DataGrid.SelectedItems property:

<DataGrid ItemsSource="{Binding YourCollectionProperty}" 
    SelectedItem="{Binding YourItemProperty}" />

With the DataGrid.SelectedItems property data bound to your YourItemProperty, you can set which item is selected in the UI by setting this property. So to move the selected item down one position, you could do something like this:

int selectedIndex = YourCollectionProperty.IndexOf(YourItemProperty);
if (YourCollectionProperty.Count > selectedIndex) 
    YourItemProperty = YourCollectionProperty.ElementAt(selectedIndex + 1);

So that is how you perform the actions of the 'Move Down' Button and the 'Move Up' Button would work similarly. Then all you would need to do is to hook up some Click or ICommand event handlers.

Sheridan
  • 68,826
  • 24
  • 143
  • 183
  • Doenst really help explainatio of what YourItemProperty is and how this is relvanant to the listview as explained was using wpf and listview – c-sharp-and-swiftui-devni Sep 03 '14 at 10:21
  • 2
    Firstly, you're welcome to the time that I spent on your answer. Secondly, really? Try reading it again: I said *You need to data bind a collection property to the `DataGrid.ItemsSource` property **and a property of the same type as the items in the collection to the `DataGrid.SelectedItems` property***. Can you see it now? – Sheridan Sep 03 '14 at 11:01
  • As I said I was already using that method with a oberservationcollection ! – c-sharp-and-swiftui-devni Sep 03 '14 at 11:22
  • 3
    Wow, you really are a rude member... I vaguely remember having a similar altercation with you before. If you spent more time reading my answer than whining, you could have worked out how to fulfil your requirements from it. I really have no inclination in helping such a rude and ignorant user any further. – Sheridan Sep 03 '14 at 11:56
  • 2
    Thank you @PatrickHofman... it's good to know that not *all* of my many hours helping on this website has been wasted. – Sheridan Sep 03 '14 at 15:02
  • lest stack saw it was serial voting ;-0 vindicated – c-sharp-and-swiftui-devni Sep 11 '14 at 14:14