Click here to Skip to main content
15,891,788 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Collections.ObjectModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using System.Windows.Threading;
using DBLayer_Lib;
using System.Data.SqlClient;
using DevExpress.Utils;
using DevExpress.Diagram.Core;
using DevExpress.XtraDiagram;
using DevExpress.XtraGrid.Views.Grid.ViewInfo;



namespace Implementer
{
  

    public partial class MainForm : Form
    {
        #region intit and globals
        public MainForm()
        {
            InitializeComponent();
            DevExpress.XtraGrid.Views.Grid.GridView gridView = new DevExpress.XtraGrid.Views.Grid.GridView();
            var transactions = new ObservableCollection<Item>();
            for (int i = 0; i <= 100; i++)
            {
                transactions.Add(new Item { Content = "Item " + i });
            }
            grdTransactions.AllowDrop = true;
            grdTransactions.DataSource = transactions;
            dgmWf.AddingNewItem += (s, e) => transactions.Remove(e.Item.Tag as Item);

        }

        Point mouseDownLocation;
        GridHitInfo gridHitInfo;

        #endregion

        #region events

        public void Mainform_Load(object sender, EventArgs e)
        {

            // TODO: This line of code loads data into the 'vA_ERP4_ADMINDataSet.SYSTEM_MODULES' table. You can move, or remove it, as needed.
            //Project intiation
            //Fill drop down for project list
            cmbProject.SelectedIndex = 0;
            DataAccess dataAccess = new DataAccess(GlobalFunctions.GetConnectionString());
            DataTable dtResult = dataAccess.ExecuteQueryDataSet("select MODULE_CODE ,MODULE_DESC from SYSTEM_MODULES where module_is_active=1").Tables[0];

            cmbProject.DisplayMember = "MODULE_DESC";
            cmbProject.ValueMember = "MODULE_CODE";
            cmbProject.DataSource = dtResult;
           
        }

        private void cmbProject_SelectedIndexChanged(object sender, EventArgs e)
        {
            lblCurrentProject.Text = cmbProject.Text;

            if (cmbProject.Text != null)
            {

                DataAccess dataAccess = new DataAccess(GlobalFunctions.GetConnectionString());
                DataTable dtTransactions = dataAccess.ExecuteQueryDataSet("select sys_trans_id, sys_trans_desc1 from WF_SYSTEM_TRANS where MODULE_CODE= '" + cmbProject.Text + "'").Tables[0];
                grdTransactions.DataSource = dtTransactions;


            }

        }

        private void btnSalesInvoice_Click(object sender, EventArgs e)
        {
            int sysTransId = 1001;
            FillTransactionDetails(sysTransId);


        }


        #endregion

        #region drag drop
        private void grdTransactions_MouseMove(object sender, MouseEventArgs e)
        {
            if (e.Button == MouseButtons.Left && CanStartDragDrop(e.Location))
            {
                StartDragDrop();
            }
        }

        private void grdTransactions_MouseDown(object sender, MouseEventArgs e)
        {
            gridHitInfo = grdVTransactions.CalcHitInfo(e.Location);
            mouseDownLocation = e.Location;
        }

        private void grdTransactions_MouseLeave(object sender, EventArgs e)
        {
            if (gridHitInfo != null)
                gridHitInfo.View.ResetCursor();
            gridHitInfo = null;

        }

        private bool CanStartDragDrop(Point location)
        {
            return gridHitInfo.InDataRow && (Math.Abs(location.X - mouseDownLocation.X) > 2 || Math.Abs(location.Y - mouseDownLocation.Y) > 2);
        }
       
        public void StartDragDrop()
        {
            var draggedRow = gridHitInfo.View.GetRow(gridHitInfo.RowHandle) as Item;
            var tool = new FactoryItemTool(" ", () => " ", diagram => new DiagramShape(BasicShapes.Rectangle) { Content = draggedRow.Content, Tag = draggedRow }, new System.Windows.Size(150, 100), false);
            dgmWf.Commands.Execute(DiagramCommandsBase.StartDragToolCommand, tool, null);
        }
      
        #endregion

        #region function
        private void FillTransactionDetails(int systemTransactionId)
        {
            //Fill document
            //Fill steps
            DataAccess dataAccess = new DataAccess(GlobalFunctions.GetConnectionString());
            DataTable transactionDetails = dataAccess.ExecuteQueryDataSet("SELECT DOC_TYPE_DESC1 FROM WF_SYSTEM_TRANS_DT WHERE SYS_TRANS_ID=1001  and MODULE_CODE= '" + cmbProject.Text + "'").Tables[0];
            transactionDetails.Rows.Add();
            grdDocuments.DataSource = transactionDetails;
            grdDocuments.Columns["Details"].DisplayIndex = 2;
            grdDocuments.Columns["Delete"].DisplayIndex = 2;


            DataTable transactionSteps = dataAccess.ExecuteQueryDataSet("select WF_STEP_DESC1 from WF_STEPS where wf_id= 10101  and MODULE_CODE= '" + cmbProject.Text + "'").Tables[0];
            transactionSteps.Rows.Add();
            grdSteps.DataSource = transactionSteps;

        }
        #endregion

      

    }

    public class Item
    {
        public string Content { get; set; }
    }
}


What I have tried:

I have tried searching for different topics that could help me but the program doesn't really tell me where the error is but I hope someone could help me with this. where in when I drag the data fro the grid control it would become a diagram on the diagram control. it worked without the fetching of data but after fetching the data it didn't work. and please help how to set the tag property automatically for each data to the said diagram. i tried by setting it with the .tag property in coding but it would take alot of work maybe there is an easier way. thanks
Posted
Comments
BillWoodruff 3-Mar-18 17:35pm    
Since you purchased DevXpress, an expensive program, why aren't you using their support ?
Member 13707117 3-Mar-18 23:32pm    
it's currently on a trial mode for now. and really didn't get the hang of it. so yeah..
BillWoodruff 4-Mar-18 0:14am    
Even without purchasing the software you can create an account on their web-site, and submit a support ticket.

go here: https://www.devexpress.com/Support/Center/Search/List/1

and here: https://www.devexpress.com/Support/Center/Search/List/1?searchString=drag%20and%20drop

and do a search on 'drag and drop'
Member 13707117 4-Mar-18 0:24am    
thank you for that I had posted a question over there after you've mentioned of their support but still hoping that there will be a higher percentage of my question being answered if I post in more than one forum.. just hoping though thanks for your help!
#realJSOP 4-Mar-18 7:54am    
It would help if you told us what PLATFORM your'e coding for. WinForms, WPF, etc...

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900