0

The data source is an Access database;
Connecting to the database - through the code;

After dragging the "node" into the TreeList, the sequence number of the "node" is updated in the "sort" field.
Problem: for a node that is being dragged, the "sort" field in the database is not updated.
For the remaining nodes that are in the same parent, the field update works correctly.

Update
Statistics
The initial state. The node "Node_1" is located in "Parent_1".

  1. "Parent_1"-> "Node_1" -> "Parent_2".
    Dragging the node "Node_1" from the parent "Parent_1" to "Parent_2". The numbering of the "sorting" field for the nodes in the database table is correct.

  2. "Parent_2". "Node_2" <-> "Node_1" <-> "Node_3".
    Dragging node "Node_1" between child nodes "Parent_2".
    For a node that is being dragged, the "sort" field in the database is not updated.
    For the remaining nodes that are in the same parent, the field update works correctly.

  3. "Parent_1" <- "Node_1" <- "Parent_2".
    Dragging node "Node_1" from parent "Parent_2" to "Parent_1" - in the line adapter.Update (dt); error: "Concurrency violation: UpdateCommand has affected 0 of the expected 1 entries."

How to make the program correctly update the “sorting” field while dragging a node in the treelist and in the database?

initial state
drag

picture with error
settings

//
using DevExpress.XtraTreeList;
using DevExpress.XtraTreeList.Nodes;

namespace rsh
{
    public partial class Form1 : Form
    {
        DataTable dt;        
        OleDbDataAdapter adapter;
        OleDbCommandBuilder AccessCommandBuilder;


        public Form1()
        {
            InitializeComponent();
        }

        private void Form1_Load(object sender, EventArgs e)
        {
            connect();

            //
            UpdateNodesPositions(treeList1.Nodes);
            treeList1.ExpandAll();
        }

        #region *** DB *** 

        public void connect()
        {
            string catBD = @"c:\test\visualStudio\csharp\01\01.accdb";
            string conBD = string.Format("Provider=Microsoft.ACE.OLEDB.12.0;Data Source={0}", catBD);

            OleDbConnection connection = new OleDbConnection(conBD);

            connection.Open();

            string query1 = "SELECT * FROM TableTreeView_12";
            OleDbCommand cmd1 = new OleDbCommand(query1, connection);

            dt = new DataTable();

            adapter = new OleDbDataAdapter(cmd1);
            AccessCommandBuilder = new OleDbCommandBuilder(adapter);

            adapter.Fill(dt);


            treeList1.KeyFieldName = "ID";
            treeList1.ParentFieldName = "PrID";

            treeList1.DataSource = dt;

        }

        public void Save()
        {
            adapter.Update(dt);
        }
        #endregion *** DB *** 

        private void treeList1_AfterDragNode(object sender, DevExpress.XtraTreeList.AfterDragNodeEventArgs e)
        {
            SaveNewRecordPosition(e);
        }

        private void SaveNewRecordPosition(NodeEventArgs e)
        {

            var nodes = e.Node.ParentNode == null
                        ? e.Node.TreeList.Nodes
                        : e.Node.ParentNode.Nodes;

            richTextBox1.Clear();
            for (var i = 0; i < nodes.Count; i++)
            {
                nodes[i].SetValue(0, i);


                string id = nodes[i].GetValue(0).ToString();
                string s = nodes[i].GetValue(1).ToString();

                richTextBox1.Text += id + " -//- " + s + "\r\n";

            }

            Save();

        }

        private void UpdateNodesPositions(TreeListNodes nodes)
        {
            var ns = new List<TreeListNode>();
            foreach (TreeListNode n in nodes)
            {
                ns.Add(n);
            }
            foreach (TreeListNode n in ns)
            {
                UpdateNodesPositions(n.Nodes);
                n.TreeList.SetNodeIndex(n, Convert.ToInt32(n.GetValue("sorting")));
            }
        }



    }
}
eusataf
  • 807
  • 1
  • 12
  • 24
  • Ensure that your have the "sorting" data field in your data table and it is the first column in TreeList (since you access this column value by using an index). – Svetlana Nov 06 '18 at 10:35
  • @Svetlana Are you talking about it? See the screen - [link](http://prntscr.com/lezpod) If you mean this, then how to solve my problem? – eusataf Nov 06 '18 at 11:48
  • @Svetlana Changed the question – eusataf Nov 06 '18 at 12:22
  • @Svetlana Once again updated the question. – eusataf Nov 06 '18 at 15:02
  • TreeList cannot affect a data adapter. It is likely that you will be able to reproduce the issue by using any standard control instead. If not, contact DevExpress Support Team (https://www.devexpress.com/Support/Center/) and send them your sample for investigation. – Svetlana Nov 08 '18 at 07:35

0 Answers0