Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
579
Drag n Drop between two UltraWinGrids
posted

Hi,

 

I wanted to drag n drop rows between two UltraGrids. (some on same form (like master details) and some on other forms)

 

Only problem is that the DragDrop event doesn't get fired when letting go the mouse with a row on the grid.

 

SelectionDrag method from childgrid (does get triggered correctly):

 private void ugvShipmentMovementsDetails_SelectionDrag(object sender, CancelEventArgs e)
        {
            if (ugvShipmentMovementsDetails.SelRows.Count > 0)
            {
                try
                {
                    DataObject drgObject = new DataObject();

                    string StrDrgObject = PrepareDetailsData();

                    drgObject.SetText(StrDrgObject);

                    string strAgendaDragDropData;
                    int blockHeight = 23;


                    StringBuilder sb = new StringBuilder();

                    foreach (UltraGridRow RowSelected in ugvShipmentMovementsDetails.SelRows)
                    {
                        sb.AppendLine(RowSelected.Cells["Shipment No."].Text.ToString() + " - " + RowSelected.Cells["Movement No."].Text.ToString());
                        blockHeight += 15;
                    }
                    strAgendaDragDropData = sb.ToString();

                    int blockWidth = 120;

                    Bitmap bitmap = new Bitmap(blockWidth + 17, blockHeight + 5);
                    Graphics g = Graphics.FromImage(bitmap);
                    using (Font f = new Font(FontFamily.GenericSansSerif, 10))
                    {
                        RectangleF rect = new RectangleF(12, 17, blockWidth - 1, blockHeight);
                        g.FillRectangle(Brushes.WhiteSmoke, rect);

                        g.DrawString(strAgendaDragDropData, f, Brushes.Navy, 16, 21);

                        Rectangle rectIcon = new Rectangle((int)(rect.X + rect.Width - 27), 17, 24, 24);
                        g.DrawRectangle(new Pen(Color.Navy, 2), 12, 17, blockWidth, blockHeight - 13);
                        g.DrawImage(ugvShipmentMovementsDetails.SourceType.LargeImage, rectIcon);
                        g.DrawImage(rscGraphicalPlanning.Cursor_Hand, 0, 0);
                    }

                    curDragCursor = clsGeneralUtils.CreateCursor(bitmap, 3, 3);
                    bitmap.Dispose();

                    Cursor.Current = curDragCursor;
                    bDragging = true;
                    this.DoDragDrop(drgObject, DragDropEffects.Copy);
                }
                catch (Exception ex)
                {
                    frmException ExceptForm = new frmException("Error", ex);
                    ExceptForm.Show();
                }
            }
        }

 

DragOver event of the master UltraGrid (on the same form, gets triggered correctly):

private void ugvGroupageFiles_DragOver(object sender, DragEventArgs e)
        {
            Object objItem = new Object();
            String strText = String.Empty;

            char SplitChar = ',';
            objItem = e.Data.GetData(DataFormats.Text);//Store the data being dragged in an object

            string[] StrObject = objItem.ToString().Split(SplitChar);

            // Examine the different drop information and set the appropriate information for the appointment
            // NOTE: The time bar being created is passed as a parameter on the e arguments
            switch (StrObject[0])
            {
                case "Shipment Movement-2003015":
                    //DropShipmentMovements(e, StrObject);
                    e.Effect = DragDropEffects.Move;
                    break;
                case "Shipment Movement-2003015-FromGroupageFile":
                    //DropShipmentMovements(e, StrObject);
                    e.Effect = DragDropEffects.Move;
                    break;
                //case "File Tpt-2002946":
                //    //DropShipmentMovements(e, StrObject);
                //    e.Effect = DragDropEffects.None;
                //    Cursor.Current = Cursors.Default;
                //    break;
                default:
                    e.Effect = DragDropEffects.None;
                    break;
            }
        }

DragDrop event of the master UltraGrid (on the same form):

private void ugvGroupageFiles_DragDrop(object sender, DragEventArgs e)
        {
            // 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 = ugvGroupageFiles.DisplayLayout.UIElement.ElementFromPoint(ugvGroupageFiles.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)
            {
                Object objItem = new Object();
                String strText = String.Empty;

                char SplitChar = ',';
                objItem = e.Data.GetData(DataFormats.Text);//Store the data being dragged in an object

                string[] StrObject = objItem.ToString().Split(SplitChar);

                // Examine the different drop information and set the appropriate information for the appointment
                // NOTE: The time bar being created is passed as a parameter on the e arguments
                switch (StrObject[0])
                {
                    case "Shipment Movement-2003015-FromGroupageFile":
                        //DropShipmentMovements(e, StrObject);
                        e.Effect = DragDropEffects.Move;

                        //TO DO: Send NAV Message
                        StringBuilder sb = new StringBuilder();
                        for (int i = 1; i < StrObject.Length; i++)
                        {
                            sb.Append(StrObject[i]);
                            if (i < StrObject.Length - 1)
                            {
                                sb.Append(" - ");
                            }
                        }
                        MessageBox.Show("Shipment Movement " + sb.ToString() + " moved to Groupage File " + ugrOver.Cells["File No."].Value.ToString());

                        break;

                    case "Shipment Movement-2003015":
                        //DropShipmentMovements(e, StrObject);
                        e.Effect = DragDropEffects.Link;

                        //TO DO: Send NAV Message
                        StringBuilder sb2 = new StringBuilder();
                        for (int i = 1; i < StrObject.Length; i++)
                        {
                            sb2.Append(StrObject[i]);
                            if (i < StrObject.Length - 1)
                            {
                                sb2.Append(" - ");
                            }
                        }
                        MessageBox.Show("Shipment Movement " + sb2.ToString() + " moved to Groupage File " + ugrOver.Cells["File No."].Value.ToString());

                        break;
                    default:
                        e.Effect = DragDropEffects.None;
                        break;
                }
            }

            LoadData(false);
        }