Question

Currently my page consist of two grid side by side, each of the grid binding a list, says GridA binding ListA and GridB binding ListB.

Both of the grid implemented Telerik DragDropManager. In most cases everything works fine, user can simply drag element from GridA and drop on GridB and both ListA and ListB will reflect accordingly.

Now I'm trying to make a checking on GridB so that whenever user drag an element from GridA, if this element existed in GridB, the element won't be added.

I noticed I can implement a drop function at GridB as below:

<telerik:RadGridView 
    ItemSource="{Binding ListB}" 
    DataContext="{Binding [someViewModel]}" 
    Drop="abc_Drop" 
    DataLoaded="abc_DataLoaded"
    x:Name="GridB">

And below will be my drop function:

private void abc_Drop(object sender, System.Windows.DragEventArgs e)
{
   var selectedItem = (T)GridA.SelectedItem;
   List<T> x = someViewModel.ListB; 
}

In order to investigate, I put a breakpoint on abc_Drop method. What I found is that, while I execute abc_Drop method, someViewMode.ListB.Count() still return 0 but once it finish, someViewModel.ListB.Count() return 1. Hence my question, where should I do the checking and prevent element added into the list conditionally? What will be executed right after drop method?

No correct solution

OTHER TIPS

I've found the answer myself.

private void abc_Drop(object sender, System.Windows.DragEventArgs e){

    e.Handled = true;
    var selectedItem = (T)GridA.SelectedItem;
    if( /*condition*/ ){
        ListB.Add(selectedItem);
    }
    GridB.Rebind();
}

By using e.Handled = true, it halted the operation and I can now implement my own logic into it

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top