WPF C#: Rearrange items in listbox via drag and drop -


Text after "

I drag the mouse through how to move the item up and down to a previously loaded listbox I am trying to

I have looked at the control. Dodradrope method from Microsoft's API, but I still can not get to do anything

I would appreciate any help since I'm new to the Visual Studio Environment.

I have tried to create one using one, have a look

< Previous> ObservableCollection & lt; Emp & gt; _empList = new reviewable collection & lt; Emp & gt; (); Public Window 1 () {InitializeComponent (); _empList Add (new ampe ("1", 22)); _empList Add (new ampe ("2", 18)); _empList Add (new ampe ("3", 29)); _empList Add (new ampe ("4", 9)); _empList Add (new ampe ("5", 29)); _empList Add (new ampe ("6", 9)); Listbox1.DisplayMemberPath = "name"; Listbox1.ItemsSource = _empList; Style itemcontainer style = new style (typeweb (listbloxime)); ItemContainerStyle.Setters.Add (New Setter (ListBoxItem.AllowDropProperty, True)); ItemContainerStyle.Setters.Add (New EventSetter (ListBoxItem.PreviewMouseLeftButtonDownEvent, New MouseButtonEventHandler (s_PreviewMouseLeftButtonDown)); ItemContainerStyle.Setters.Add (New EventSetter (ListBoxItem.DropEvent, New DragEventHandler (listbox1_Drop)); Listbox1.ItemContainerStyle = itemContainerStyle; }

Drag and process

  zero s_PreviewMouseLeftButtonDown (object sender, MouseButtonEventArgs e) {if (this is ListBoxItem) as {ListBoxItem draggedItem = ListBoxItem this ; Dragrap.dotragroup (drag item, drag item.datacontext, dragfiffect.move); Drag ITAM. Has been selected = true; }} Void listbox1_Drop (Object Sender, DragEventEurge E) {Emp droppedData = e.Data.GetData (typeof (emp)) as an amp; Emp target = (ListBoxItem) (Sender)). DataContext as Emp; Int removed idx = listbox1.Items.IndexOf (omitted data); Int targetIdx = listbox1.Items.IndexOf (target); If (deleted IDX & lt; targetIdx) {_empList.Insert (target ID + 1, omitted data); _empList.RemoveAt (removedIdx); } Else {int remIdx = removedIdx + 1; If (_empList.Count + 1 & gt; remIdx) {_empList.Insert (target ID, data omitted); _empList.RemoveAt (remIdx); }}}  

Note:

  • is useless in a matter of implementation, because it PreviewMouseLeftButtonDown event, find uses dragged items not selected
  • and also need a better solution for an easy drop to implement the target list box objects and listbox itself - this
May

Comments

Popular posts from this blog

c# - sqlDecimal to decimal clr stored procedure Unable to cast object of type 'System.Data.SqlTypes.SqlDecimal' to type 'System.IConvertible' -

Calling GetGUIThreadInfo from Outlook VBA -

Obfuscating Python code? -