private void ultraGrid2_SelectionDrag(object sender, CancelEventArgs e) { ultraGrid2.DoDragDrop(ultraGrid2.Selected.Rows, DragDropEffects.Move); } private void ultraGrid1_DragOver(object sender, DragEventArgs e) { e.Effect = DragDropEffects.Move; UltraGrid grid = sender as UltraGrid; Point pointInGridCoords = grid.PointToClient(new Point(e.X, e.Y)); if (pointInGridCoords.Y < 20) // Scroll up. this.ultraGrid1.ActiveRowScrollRegion.Scroll(RowScrollAction.LineUp); else if (pointInGridCoords.Y > grid.Height - 20) // Scroll down. this.ultraGrid1.ActiveRowScrollRegion.Scroll(RowScrollAction.LineDown); } private int _MinSetID = -1; private void ultraGrid1_DragDrop(object sender, DragEventArgs e) { try { int dropIndex; //Get the position on the grid where the dragged row(s) are to be dropped. //get the grid coordinates of the row (the drop zone) UIElement uieOver = ultraGrid1.DisplayLayout.UIElement.ElementFromPoint(ultraGrid1.PointToClient(new Point(e.X, e.Y))); //get the row that is the drop zone/or where the dragged row is to be dropped UltraGridRow ugrOver = uieOver.GetContext(typeof(UltraGridRow), true) as UltraGridRow; if (ugrOver != null) { dropIndex = ugrOver.Index; //index/position of drop zone in grid //get the dragged row(s)which are to be dragged to another position in the grid SelectedRowsCollection SelRows = (SelectedRowsCollection)e.Data.GetData(typeof(SelectedRowsCollection)) as SelectedRowsCollection; //get the count of selected rows and drop each starting at the dropIndex if (SelRows.Count > 0) { if (SelRows[0].Band.Key == "ReportSet") foreach (UltraGridRow aRow in SelRows) { string serieID = aRow.Cells["ReportSeries.ID"].Value.ToString(); DataRow dataRow = ((DataRowView)aRow.ListObject).Row; if (ugrOver.Band.Key == "ReportSeries") { dataRow["ReportSeries.ID"] = ugrOver.Cells["ID"].Value; dataRow["SerieName"] = ugrOver.Cells["SerieName"].Value; dataRow["SiteID"] = ugrOver.Cells["SiteID"].Value; } else { dataRow["ReportSeries.ID"] = ugrOver.ParentRow.Cells["ID"].Value; dataRow["SerieName"] = ugrOver.ParentRow.Cells["SerieName"].Value; dataRow["SiteID"] = ugrOver.ParentRow.Cells["SiteID"].Value; } dataRow["SerieID"] = dataRow["ReportSeries.ID"]; SetModifiedDate(dataRow["SerieID"].ToString()); ultraGrid1.Rows.Move(aRow, dropIndex); if (dataRow["SerieID"].ToString() == serieID) //serie ID didn't changed aRow.ParentCollection.Move(aRow, dropIndex); } else if(SelRows[0].Band.Key != "ReportSeries") foreach (UltraGridRow aRow in SelRows) { DataRow row = _ReportSeries.Tables["ReportSet"].NewRow(); row["ReportSet.ID"] = _MinSetID; _MinSetID--; if (ugrOver.Band.Key == "ReportSeries") { row["ReportSeries.ID"] = ugrOver.Cells["ID"].Value; row["SerieName"] = ugrOver.Cells["SerieName"].Value; row["SiteID"] = ugrOver.Cells["SiteID"].Value; } else { row["ReportSeries.ID"] = ugrOver.ParentRow.Cells["ID"].Value; row["SerieName"] = ugrOver.ParentRow.Cells["SerieName"].Value; row["SiteID"] = ugrOver.ParentRow.Cells["SiteID"].Value; } SetModifiedDate(row["ReportSeries.ID"].ToString()); row["ReportMemorized"] = aRow.Cells["ID"].Value; row["ReportMemorized.ID"] = aRow.Cells["ID"].Value; row["ReportType"] = aRow.Cells["ReportType"].Value; row["Order"] = -1; row["Expression"] = ""; row["SerieID"] = row["ReportSeries.ID"]; row["ConfigXML"] = aRow.Cells["ConfigXML"].Value; row["Title"] = aRow.Cells["Title"].Value; _ReportSeries.Tables["ReportSet"].Rows.Add(row); } ultraGrid1.Refresh(); } } } catch (Exception ex) { MessageBox.Show(ex.Message, "Error during drag&drop", MessageBoxButtons.OK, MessageBoxIcon.Error); } } private void ultraGrid1_SelectionDrag(object sender, CancelEventArgs e) { ultraGrid1.DoDragDrop(ultraGrid1.Selected.Rows, DragDropEffects.Move); }