Completed
Last Updated: 20 Feb 2014 15:17 by ADMIN
ADMIN
Dess | Tech Support Engineer, Principal
Created on: 03 Jan 2014 02:09
Category:
Type: Bug Report
1
FIX. RadListView - column's DragDrop behavior causes RadListView header glitch in DetailsView
To reproduce:
- add two RadListView controls and use the following code:

this.radListView1.ViewType = ListViewType.DetailsView;
this.radListView1.Columns.Add("1.Drag To Right Page");
this.radListView1.Columns.Add("2.Drag To Right Page");
this.radListView1.Columns.Add("3.Drag To Right Page");

this.radListView2.ViewType = ListViewType.DetailsView;
this.radListView2.Columns.Add("1.Drag To Left Page");
this.radListView2.Columns.Add("2.Drag To Left Page");
this.radListView2.Columns.Add("3.Drag To Left Page");

Run the application and drag a column from one list view to another list view. You will notice that when the dragged column is dropped over different listview than its owner, RadListView behave strangely.

Workaround: implement custom DetailListViewDragDropService and prevent the possibility to drag over different listview than the dragged column's owner:

public Form1()
{
    InitializeComponent();

    this.radListView1.ViewType = ListViewType.DetailsView;
    DetailListViewElement detailListViewElement1 = this.radListView1.ListViewElement.ViewElement as DetailListViewElement ;
    if (detailListViewElement1 != null)
    {
        FieldInfo fi = detailListViewElement1.GetType().GetField("columnDragDropService", BindingFlags.NonPublic | BindingFlags.Instance);
        fi.SetValue(detailListViewElement1, new CustomDragDropService(detailListViewElement1));
    }
    this.radListView1.Columns.Add("1.Drag To Right Page");
    this.radListView1.Columns.Add("2.Drag To Right Page");
    this.radListView1.Columns.Add("3.Drag To Right Page");
  
    this.radListView2.ViewType = ListViewType.DetailsView;
    DetailListViewElement detailListViewElement2 = this.radListView2.ListViewElement.ViewElement as DetailListViewElement ;
    if (detailListViewElement2 != null)
    {
        FieldInfo fi = detailListViewElement2.GetType().GetField("columnDragDropService", BindingFlags.NonPublic | BindingFlags.Instance);
        fi.SetValue(detailListViewElement2, new CustomDragDropService(detailListViewElement2));
    }
    this.radListView2.Columns.Add("1.Drag To Left Page");
    this.radListView2.Columns.Add("2.Drag To Left Page");
    this.radListView2.Columns.Add("3.Drag To Left Page");
}

public class CustomDragDropService : DetailListViewDragDropService
{
    public CustomDragDropService(DetailListViewElement owner) : base(owner)
    {
    }

    protected override void OnPreviewDragOver(Telerik.WinControls.RadDragOverEventArgs e)
    { 
        DetailListViewCellElement targetElement = e.HitTarget as DetailListViewCellElement;
        ListViewDetailColumn targetColumn = targetElement.Data;
        DetailListViewCellElement draggedElement = e.DragInstance as DetailListViewCellElement;
        ListViewDetailColumn draggedColumn = draggedElement.Data;
        if (targetColumn == null || draggedColumn == null ||
            targetColumn.Owner != draggedColumn.Owner)
        {
            e.CanDrop = false;
            return;
        }
      
        base.OnPreviewDragOver(e);
    }
}
0 comments