Click here to Skip to main content
15,885,546 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
I am using drag and drop functionality by devexpress to fill a listbox by dragging items from a data grid

the problem is not related to devexpress or dragging and dropping, it works just fine but the listbox.Items.Count is always 0 even if the listbox contains items

I've been looking for a solution and the best guess is that the listbox filled by end-user will always be empty in code for some reason.

is there a way to actually get the listbox.items and manipulate them in code for this scenario

Edit/

it's in wpf. I just added a list box with the drag and drop functionality and a button that retrieves the number of items in the listbox (listbox.Items.count.ToString()). in the beinning the listbox is empty and when the end-user adds items to the listbox and clicks the button it should return the number of items they added. instead t always returns 0. Maybe the added items (by the end user) are not counted

What I have tried:

private void OnDrop(object sender, DevExpress.Xpf.Core.DropRecordEventArgs e)
        {
            
            if (e.Data.GetDataPresent(typeof(RecordDragDropData)))
             {
                var data = (RecordDragDropData)e.Data.GetData(typeof(RecordDragDropData));
                var newRecords = data.Records.OfType<Person>().Select(x => new Employee(XpoDefault.Session) { EmpName= x.PerName}).ToArray();
                if (newRecords.Length > 0)
                {
                    DataObject dataObject = new DataObject();
                    dataObject.SetData(new RecordDragDropData(newRecords));
                    e.Data = dataObject;

                }

            }
        }
Posted
Updated 22-Oct-20 9:58am
v2
Comments
BillWoodruff 21-Oct-20 20:53pm    
WPF ? WinForms ? Show the code where you access ListBox.Items
izz moe 22-Oct-20 11:54am    
it's in wpf. I just added a list box with the drag and drop functionality and a button that retrieves the number of items in the listbox (listbox.Items.count.ToString()). in the beinning the listbox is empty and when the end-user adds items to the listbox and clicks the button it should return the number of items they added. instead t always returns 0. Maybe the added items (y the end user) are not counted
BillWoodruff 22-Oct-20 12:12pm    
Please edit your original post so it includes this information.

If you are using a DevExpress Listxxx Control, be aware that its properties, methods, events, etc. are probably different than the native WPF Control. You may need to study the DevX docs, and/or require support from DevX ... which you are entitled to when you purchase their software.

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