private void InnerControlOnDrop(object theSender, DragDropUserControl.DragDropEventArgs theE) { var aSender = theSender as DragDropUserControl; if (aSender == null) { return; } var aRowIndexFromMouseDown = theE.RowIndexFromMouseDown; var aRowIndexOfItemUnderMouseToDrop = theE.RowIndexOfItemUnderMouseToDrop; var aColumnIndexFromMouseDown = theE.ColumnIndexFromMouseDown; var aColumnIndexOfItemUnderMouseToDrop = theE.ColumnIndexOfItemUnderMouseToDrop; if (aRowIndexFromMouseDown == 0 || aRowIndexOfItemUnderMouseToDrop == 0 || aColumnIndexFromMouseDown == 0 || aColumnIndexOfItemUnderMouseToDrop == 0) { aSender.AllowThisOneColumnDragDrop = false; aSender.AllowThisOneRowDragDrop = false; } if (aRowIndexFromMouseDown <= parameters.RowLabels.Count && aRowIndexOfItemUnderMouseToDrop > parameters.RowLabels.Count) { aSender.AllowThisOneRowDragDrop = false; } if (aRowIndexFromMouseDown > parameters.RowLabels.Count && aRowIndexOfItemUnderMouseToDrop <= parameters.RowLabels.Count) { aSender.AllowThisOneRowDragDrop = false; } if (aColumnIndexFromMouseDown <= parameters.ColumnLabels.Count && aColumnIndexOfItemUnderMouseToDrop > parameters.ColumnLabels.Count) { aSender.AllowThisOneColumnDragDrop = false; } if (aColumnIndexFromMouseDown > parameters.ColumnLabels.Count && aColumnIndexOfItemUnderMouseToDrop <= parameters.ColumnLabels.Count) { aSender.AllowThisOneColumnDragDrop = false; } if (aRowIndexFromMouseDown > activeRowCount || aRowIndexOfItemUnderMouseToDrop > activeRowCount) { aSender.AllowThisOneRowDragDrop = false; } if (aRowIndexFromMouseDown == aRowIndexOfItemUnderMouseToDrop) { aSender.AllowThisOneRowDragDrop = false; } if (aColumnIndexFromMouseDown == aColumnIndexOfItemUnderMouseToDrop) { aSender.AllowThisOneColumnDragDrop = false; } if (ReOrdered != null) { TriggerReOrder(aRowIndexFromMouseDown, aRowIndexOfItemUnderMouseToDrop, aColumnIndexFromMouseDown, aColumnIndexOfItemUnderMouseToDrop, aSender); } }
private void TriggerReOrder(int theRowIndexFromMouseDown, int theRowIndexOfItemUnderMouseToDrop, int theColumnIndexFromMouseDown, int theColumnIndexOfItemUnderMouseToDrop, DragDropUserControl theSender) { if (theSender.AllowThisOneRowDragDrop && theRowIndexFromMouseDown <= parameters.RowLabels.Count && theRowIndexOfItemUnderMouseToDrop <= parameters.RowLabels.Count) { if (theRowIndexFromMouseDown > theRowIndexOfItemUnderMouseToDrop) { var aSwapValue = rowLabels[theRowIndexFromMouseDown]; int aI = theRowIndexFromMouseDown; for (; aI > theRowIndexOfItemUnderMouseToDrop; aI--) { rowLabels[aI] = rowLabels[aI - 1]; } rowLabels[aI] = aSwapValue; } else { var aSwapValue = rowLabels[theRowIndexFromMouseDown]; int aI = theRowIndexFromMouseDown; for (; aI < theRowIndexOfItemUnderMouseToDrop; aI++) { rowLabels[aI] = rowLabels[aI + 1]; } rowLabels[aI] = aSwapValue; } ReOrderEventArgs aE = new ReOrderEventArgs(rowLabels.Values.ToList(), columnLabels.Values.ToList()); ReOrdered(this, aE); } else if (theSender.AllowThisOneColumnDragDrop && theColumnIndexFromMouseDown <= parameters.ColumnLabels.Count && theColumnIndexOfItemUnderMouseToDrop <= parameters.ColumnLabels.Count) { if (theColumnIndexFromMouseDown > theColumnIndexOfItemUnderMouseToDrop) { var aSwapValue = rowLabels[theColumnIndexFromMouseDown]; int aI = theColumnIndexFromMouseDown; for (; aI > theRowIndexOfItemUnderMouseToDrop; aI--) { rowLabels[aI] = rowLabels[aI - 1]; } rowLabels[aI] = aSwapValue; } else { var aSwapValue = rowLabels[theColumnIndexFromMouseDown]; int aI = theColumnIndexFromMouseDown; for (; aI < theColumnIndexOfItemUnderMouseToDrop; aI++) { rowLabels[aI] = rowLabels[aI + 1]; } rowLabels[aI] = aSwapValue; } ReOrderEventArgs aE = new ReOrderEventArgs(rowLabels.Values.ToList(), columnLabels.Values.ToList()); ReOrdered(this, aE); } }
private void InitializeInnerControl() { DataTable aDataTable = new DataTable(); int aColumnCount = parameters.RowLabels.Aggregate(1, (current, aLabel) => current * parameters.Data[aLabel].Count); aColumnCount += parameters.ColumnLabels.Count; var aColumnHeaders = CreateColumnHeaders(aColumnCount); foreach (var aHeader in aColumnHeaders) { if (!aDataTable.Columns.Contains(aHeader)) { aDataTable.Columns.Add(aHeader); } } List<List<object>> aRowLabelsData = CreateHeadersData(parameters.RowLabels); for (int aI = 0; aI < parameters.RowLabels.Count; aI++) { List<object> aRow = new List<object>(); for (int aCount = 0; aCount < parameters.ColumnLabels.Count; aCount++) { aRow.Add(string.Empty); } foreach (var aSubList in aRowLabelsData) { aRow.Add(aSubList[aI]); } aDataTable.Rows.Add(aRow.ToArray()); } List<List<object>> aColumnLabelsData = CreateHeadersData(parameters.ColumnLabels); foreach (var aSubList in aColumnLabelsData) { aDataTable.Rows.Add(aSubList.ToArray()); } activeRowCount = aDataTable.Rows.Count; for (int aI = activeRowCount + 1; aI < TOTAL_ROW; aI++) { aDataTable.Rows.Add(new List<object>().ToArray()); } innerControl = new DragDropUserControl(aDataTable); innerControl.OnDrop += InnerControlOnDrop; ChangeInerControlStyle(); }