private void DoAction(DualListAction dualListAction, bool remove, int index) { DualListCancelEventArgs e = new DualListCancelEventArgs(dualListAction, ListBoxFrom.Items[index]); if (BeforeAction != null) { BeforeAction(this, e); } if (!e.Cancel) { int newIndex = ListBoxTo.Items.Add(e.Item); ListBoxTo.SelectedIndices.Add(newIndex); if (remove) { listBoxFrom.Items.RemoveAt(index); } if (AfterAction != null) { DualListActionEventArgs f = new DualListActionEventArgs(dualListAction, e.Item, newIndex); AfterAction(this, f); } } }
public DualListCancelEventArgs( DualListAction action, object item ) { Action = action; Item = item; Cancel = false; }
private void DoSelected( DualListAction dualListAction ) { ListBoxTo.SelectedIndices.Clear(); if ( ListBoxFrom.SelectionMode == SelectionMode.One ) { if ( ListBoxFrom.SelectedIndex > -1 ) { int i = ListBoxFrom.SelectedIndex; if ( dualListAction == DualListAction.MoveSelected ) { DoAction( dualListAction, true, i ); } else // copy { DoAction( dualListAction, false, i ); i++; } if ( i >= listBoxFrom.Items.Count ) { i = listBoxFrom.Items.Count - 1; } listBoxFrom.SelectedIndex = i; } } else // multi { foreach ( int x in listBoxFrom.SelectedIndices ) { DoAction( dualListAction, false, x ); } int i; if ( listBoxFrom.SelectedIndices.Count > 0 ) { i = listBoxFrom.SelectedIndices[listBoxFrom.SelectedIndices.Count - 1] + 1; } else { return; } for ( int t = listBoxFrom.Items.Count - 1; t >= 0; t-- ) { if ( dualListAction == DualListAction.MoveSelected ) { if ( listBoxFrom.SelectedIndices.Contains( t ) ) { i = t; listBoxFrom.Items.RemoveAt( t ); } } else // copy { listBoxFrom.SetSelected( t, false ); } } if ( i > listBoxFrom.Items.Count ) { i = listBoxFrom.Items.Count - 1; } if ( i > -1 && listBoxFrom.Items.Count > i ) { listBoxFrom.SetSelected( i, true ); } } }
private void DoAction( DualListAction dualListAction, bool remove, int index ) { DualListCancelEventArgs e = new DualListCancelEventArgs( dualListAction, ListBoxFrom.Items[index] ); if ( BeforeAction != null ) { BeforeAction( this, e ); } if ( !e.Cancel ) { int newIndex = ListBoxTo.Items.Add( e.Item ); ListBoxTo.SelectedIndices.Add( newIndex ); if ( remove ) { listBoxFrom.Items.RemoveAt( index ); } if ( AfterAction != null ) { DualListActionEventArgs f = new DualListActionEventArgs( dualListAction, e.Item, newIndex ); AfterAction( this, f ); } } }
private void DoSelected(DualListAction dualListAction) { ListBoxTo.SelectedIndices.Clear(); if (ListBoxFrom.SelectionMode == SelectionMode.One) { if (ListBoxFrom.SelectedIndex > -1) { int i = ListBoxFrom.SelectedIndex; if (dualListAction == DualListAction.MoveSelected) { DoAction(dualListAction, true, i); } else // copy { DoAction(dualListAction, false, i); i++; } if (i >= listBoxFrom.Items.Count) { i = listBoxFrom.Items.Count - 1; } listBoxFrom.SelectedIndex = i; } } else // multi { foreach (int x in listBoxFrom.SelectedIndices) { DoAction(dualListAction, false, x); } int i; if (listBoxFrom.SelectedIndices.Count > 0) { i = listBoxFrom.SelectedIndices[listBoxFrom.SelectedIndices.Count - 1] + 1; } else { return; } for (int t = listBoxFrom.Items.Count - 1; t >= 0; t--) { if (dualListAction == DualListAction.MoveSelected) { if (listBoxFrom.SelectedIndices.Contains(t)) { i = t; listBoxFrom.Items.RemoveAt(t); } } else // copy { listBoxFrom.SetSelected(t, false); } } if (i > listBoxFrom.Items.Count) { i = listBoxFrom.Items.Count - 1; } if (i > -1) { listBoxFrom.SetSelected(i, true); } } }
public DualListActionEventArgs( DualListAction action, object item, int index ) { Action = action; Item = item; Index = index; }
public DualListCancelEventArgs(DualListAction action, object item) { Action = action; Item = item; Cancel = false; }
public DualListActionEventArgs(DualListAction action, object item, int index) { Action = action; Item = item; Index = index; }