This is a migrated thread and some comments may be shown as answers.

transfermod = copy

7 Answers 110 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
appdev
Top achievements
Rank 1
appdev asked on 22 Jul 2009, 04:41 PM
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.

7 Answers, 1 is accepted

Sort by
0
Veselin Vasilev
Telerik team
answered on 23 Jul 2009, 08:38 AM
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.
0
appdev
Top achievements
Rank 1
answered on 23 Jul 2009, 11:20 AM

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

0
Veselin Vasilev
Telerik team
answered on 23 Jul 2009, 11:45 AM
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.
0
appdev
Top achievements
Rank 1
answered on 23 Jul 2009, 01:33 PM
 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.
0
Shinu
Top achievements
Rank 2
answered on 24 Jul 2009, 10:21 AM
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.
0
appdev
Top achievements
Rank 1
answered on 24 Jul 2009, 02:50 PM
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);  
                    }  
                }   
            }   
        }  
0
appdev
Top achievements
Rank 1
answered on 24 Jul 2009, 05:42 PM
I THINK I GOT IT. THANKS FOR YOUR HELP
Tags
ListBox
Asked by
appdev
Top achievements
Rank 1
Answers by
Veselin Vasilev
Telerik team
appdev
Top achievements
Rank 1
Shinu
Top achievements
Rank 2
Share this question
or