transfermod = copy

8 posts, 0 answers
  1. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 22 Jul 2009 Link to this post

    so i set transfermode = copy. that works great if i didn't have anything at the start for listbox2. but when i predefine both listboxes like this
    listbox1
    1
    2
    3

    listbox2
    2

    it will still transfer 2 over. so how do i get it not too in client side. thank you for your help.
  2. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Jul 2009 Link to this post

    Hello Duy,

    Can you please explain in more detail what is the expected behavior?


    Best wishes,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 23 Jul 2009 Link to this post

    when i first come to the page, i will see two listboxes right
    listbox1                          listbox2
    1                                
    2
    3

    like that. transfermode is copy. so if you move 2 over and try to move it again, you can't. this is how transfermode = copy works. but if when  i come to the page and it has this

    listbox1                   listbox2

    1                               2

    2

    3

     

    now if i transfer 2 over, the 2 will still get transfer eventhough there's already a 2 in that listbox2. and the transfermode is copy. so how do i stop that from happening. i hope this is better.thanks

  4. Veselin Vasilev
    Admin
    Veselin Vasilev avatar
    2992 posts

    Posted 23 Jul 2009 Link to this post

    Hello Duy,

    I tried to reproduce the problem using this code, but to no avail:

    <telerik:RadListBox ID="RadListBox1" runat="server" AllowTransfer="True" Height="150" 
        TransferMode="Copy" TransferToID="RadListBox2"
        <Items> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem1" /> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem2" /> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem3" /> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem4" /> 
        </Items> 
    </telerik:RadListBox> 
     
    <telerik:RadListBox runat="server" ID="RadListBox2" Height="150"
        <Items> 
            <telerik:RadListBoxItem runat="server" Text="RadListBoxItem2" /> 
        </Items> 
    </telerik:RadListBox> 

    So, when the page loads the second listbox has an item - RadListBoxItem2. If you try to transfer the same item from RadListBox1 - nothing will happen. I am using the official Q2 2009 release.

    Am I missing something?

    Greetings,
    Veselin Vasilev
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  5. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 23 Jul 2009 Link to this post

     function OnClientTransferring(sender, e) {debugger    
                    //cancel the event    
                    e.set_cancel(true);    
                    
                    //manually transfer the appropriate items    
                    var items = e.get_items();    
                    for (var i = 0; i < items.length; i++) {    
                        var item = items[i];                        
                        if (item.get_value() != "0" && item.get_value() != "") {    
                            sender.transferItem(item, e.get_sourceListBox(), e.get_destinationListBox());    
                            if (item.get_value()   
                        }    
                    }    
                }    
     
    i also have this at the begining too this might cause it to do that. so if i want to keep that function still but disable it to transfer when the item already there. what do i need to do. thanks.
  6. Shinu
    Shinu avatar
    17764 posts
    Member since:
    Mar 2007

    Posted 24 Jul 2009 Link to this post

    Hi Duy,

    I modified your code in order to achieve the desired functionality. Give a try with the following client side code.

    JavaScript:
     
    <script type="text/javascript"
    function OnClientTransferring(sender, e) 
        //cancel the event     
        e.set_cancel(true);     
        var flag= 0; 
        //manually transfer the appropriate items     
        var items = e.get_items();     
        for (var i = 0; i < items.length; i++) 
        {     
            var item = items[i];   
            var items2 = e.get_destinationListBox().get_items();     
            for (var j = 0; j < items2.get_count(); j++) 
            {     
                var item1 = items2.getItem(j);                      
                if (item1.get_value() == item.get_value())  
                {                   
                  e.set_cancel(true); 
                  alert('Cannot transfer'); 
                  flag = 1;                                    
                } 
            }       
            if(flag) 
            { 
                break
            }      
            if (item.get_value() != "0" && item.get_value() != "")  
            {     
                sender.transferItem(item, e.get_sourceListBox(), e.get_destinationListBox());     
            }         
        }     
    }   
    </script> 

    Shinu.
  7. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 24 Jul 2009 Link to this post

    i just found out what the problem is. it was my stupidity for not having the same value when i preloaded the listbox2
    but now i run into new problem . with the code below, i can transfer them over by double click, by one at a time button, or by all. however when do all, it transfer everything including item with text = '0' . so i tried to take out the else statment, and that would just not do anything when i click on transfer all button. can you help me with this. thanks
    function OnClientTransferring(sender, args)   
            {   
                if(args.get_items().length >0)   
                {   
                    for(var i=0; i< args.get_items().length; i++ )   
                    {   
                        var text = args.get_items()[i].get_value();   
                        alert(text);  
                        if(text == '0' || text == '' || !args.get_items()[i].get_isEnabled())   
                        {   
                            args.set_cancel(true);   
                            //alert('The item cannot be transfered !');   
                        }   
                        else 
                        {  
                            args.set_cancel(false);  
                        }  
                    }   
                }   
            }  
  8. appdev
    appdev avatar
    223 posts
    Member since:
    Sep 2008

    Posted 24 Jul 2009 Link to this post

    I THINK I GOT IT. THANKS FOR YOUR HELP
Back to Top