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

Question about trasnferring items programmatically

5 Answers 119 Views
ListBox
This is a migrated thread and some comments may be shown as answers.
Manikanta Kiran
Top achievements
Rank 1
Manikanta Kiran asked on 21 Dec 2009, 03:10 PM
Hi,

I have two list boxes : available & selected values.

When I'm allowing edits , I need to pre-populate the available & selected values. So I have tried doing the transfer programmatically :

            radLstAvailable.DataSource = dataList;   
            radLstAvailable.DataTextField = "Name";  
            radLstAvailable.DataValueField = "ID";  
            radLstAvailable.DataBind();  
 
            if (edit)  
            {  
                List<Steps> steps = DataSvcClient.GetSteps();  
 
                radLstAvailable.TransferToID = "radLstSelected";  
 
                foreach (Step step in steps)  
                {  
                    RadListBoxItem lbItem = radLstAvailable.Items.Where(item => item.Value == step.ID.ToString()).FirstOrDefault();  
 
 
                    if (lbItem != null)  
                    {  
                        if (step.Order == 0)  
                            lbItem.Checked = true;  
                          
                        radLstAvailable.Transfer(lbItem, radLstAvailable, radLstSelected);  
                    }  
                }  
            } 

It is transferring the items but not removing them from available values list box. Am I missing something ?

Please advice.

Thanks
Kiran

5 Answers, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 21 Dec 2009, 06:02 PM
Hi Manikanta Kiran,

Please make sure that you have set the TransferMode of the source RadListBox to Move. Does the issue persist?

Kind regards,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manikanta Kiran
Top achievements
Rank 1
answered on 21 Dec 2009, 06:19 PM
Genady,

Thanks,  I tried setting the 'TranserMode' to 'Move'. It did not work.

Thanks
Kiran
0
Genady Sergeev
Telerik team
answered on 24 Dec 2009, 02:54 PM
Hi Manikanta Kiran,

I suppose that the ListBox is rebound after you have moved the items. Have you tried to move

radLstAvailable.DataSource = dataList;  
radLstAvailable.DataTextField = "Name"
radLstAvailable.DataValueField = "ID"
radLstAvailable.DataBind();

inside the If(edit) conditional statement? I

I have tried to reproduce the fault in a sample project, unfortunately, no avail. I am attaching my sample project. Can you modify it in a way that reproduces the problem?

Sincerely yours,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
0
Manikanta Kiran
Top achievements
Rank 1
answered on 05 Jan 2010, 04:42 PM
Thanks. I checked your project and it worked for me as  expected. I dont think the issue is with the listbox transfer method, which you demonstrated with the sample project.

I used a user control as modal popup for editing items in a rad grid. The user control has the two list boxes. I implemented the XYZ_DataBinding event handler to load the data in the edit pop-up. (Ref :  http://demos.telerik.com/aspnet-ajax/grid/examples/dataediting/usercontroleditform/defaultcs.aspx)

I realized that if  I set the datasource of the listboxes to null in the  DataBinding event handler , the transfer is working as expected. I'm not sure why the datasource needs to be set to null ?

protected void EmployeeDetails_DataBinding(object sender, System.EventArgs e)  
        {  
            ArrayList tocs = new ArrayList(new string[] { "Dr.", "Mr.", "Mrs.", "Ms." });  
 
            ddlTOC.DataSource = tocs;  
            ddlTOC.DataBind();  
 
            object tocValue = DataBinder.Eval(DataItem, "TitleOfCourtesy");  
 
            if (tocValue == DBNull.Value)  
            {  
                tocValue = "Mrs.";  
            }  
            ddlTOC.SelectedIndex = tocs.IndexOf((string)tocValue);  
            ddlTOC.DataSource = null;  // WHY DO WE SET THIS TO NULL ?
        }  
 


Thanks for your help.

Regards,
Kiran
0
Accepted
Genady Sergeev
Telerik team
answered on 07 Jan 2010, 09:53 AM
Hi Manikanta Kiran,

This is an issue specific to the RadComboBox and the RadListBox. If the DataSource is not set to null, in a later moment, the Combo/Listbox is going to be rebound. Please, excuse us for this inconvenience.

All the best,
Genady Sergeev
the Telerik team

Instantly find answers to your questions on the new Telerik Support Portal.
Watch a video on how to optimize your support resource searches and check out more tips on the blogs.
Tags
ListBox
Asked by
Manikanta Kiran
Top achievements
Rank 1
Answers by
Genady Sergeev
Telerik team
Manikanta Kiran
Top achievements
Rank 1
Share this question
or