Remove RadListItem from Code Behind

8 posts, 0 answers
  1. Mitch
    Mitch avatar
    4 posts
    Member since:
    Feb 2019

    Posted 15 Feb Link to this post

    I have two RadListBoxes I am able to drag and drop items between the two without problems, but I have one specific RadlistItem that when I add it to the other listbox I want to remove the existing list items in the code behind, but so far it keeps giving and error like Outside Index or something similar when I try to remove those list Items.  Any help or Ideas would be appreciated.

     

    Thanks,

  2. Peter Milchev
    Admin
    Peter Milchev avatar
    586 posts

    Posted 20 Feb Link to this post

    Hi Mitch,

    Here is a sample implementation that clears the destination ListBox items if the "Item 3" item is transferred: 

    <telerik:RadListBox runat="server" ID="RadListBox1" AutoPostBackOnTransfer="True" TransferToID="RadListBox2" AllowTransfer="true" OnTransferring="RadListBox1_Transferring">
        <Items>
            <telerik:RadListBoxItem Text="Item 1" />
            <telerik:RadListBoxItem Text="Item 2" />
            <telerik:RadListBoxItem Text="Item 3" />
            <telerik:RadListBoxItem Text="Item 4" />
        </Items>
    </telerik:RadListBox>
    <telerik:RadListBox runat="server" ID="RadListBox2" >
        <Items>
            <telerik:RadListBoxItem Text="Secondary Item 1" />
            <telerik:RadListBoxItem Text="Secondary Item 2" />
            <telerik:RadListBoxItem Text="Secondary Item 3" />
            <telerik:RadListBoxItem Text="Secondary Item 4" />
        </Items>
    </telerik:RadListBox>

    protected void RadListBox1_Transferring(object sender, Telerik.Web.UI.RadListBoxTransferringEventArgs e)
    {
        if (e.Items[0].Text == "Item 3")
        {
            e.DestinationListBox.Items.Clear();
        }
    }


    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  3. Mitch
    Mitch avatar
    4 posts
    Member since:
    Feb 2019

    Posted 20 Feb Link to this post

    Error Message: Non-negative number required. Parameter name: capacity

    If I drag and drop (at the bottom of the list box) it works.

     If I drag and drop (at the top of the list box or insert in the middle of

    what's already there) I get the error.

    Thanks for the help so far.

     

  4. Peter Milchev
    Admin
    Peter Milchev avatar
    586 posts

    Posted 22 Feb Link to this post

    Hello Mitch,

    Is it possible to replicate the issue with the markup that I have provided? 

    If yes, please provide more detailed reproduction steps (a screencast would be the best) so that we can check it on our side. 

    If not, please prepare a sample runnable project showing the issue and attach it to an official support ticket. That would allow us to investigate locally your exact scenario and provide more accurate and specific suggestions. 

    Once we have a solution, we can share it here for convenience and better visibility from the community.

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  5. Mitch
    Mitch avatar
    4 posts
    Member since:
    Feb 2019

    Posted 25 Feb Link to this post

    There are two Radlistboxes.

     

    When the application initially executes there will be 32 teams plus a

    "FINAL" team within the first listbox. Users are free to drag and drop between the two listboxes, however, when the

    "FINAL" team is dragged over to the 2nd listbox then anything that was

    previously in the 2nd listbox needs to be deleted/removed.

     

    I have attached the code if it would be easier I could send a zip file with the solution that way you don't have to set it up let me know.

    Thanks,

    <%@ Master Language="C#" AutoEventWireup="true" CodeFile="NFL_Teams.master.cs" Inherits="NFL_Teams" %>
     
     
     
    <!DOCTYPE html>
     
      
     
     
     
     
    <head id="Head1" runat="server">
     
     
     
    <title>G2 Adjudication</title>
     
     
     
    <meta http-equiv="cache-control" content="no-cache" />
     
     
     
    <meta http-equiv="pragma" content="no-cache" />
     
     
     
    <meta http-equiv="expires" content="0" />
     
     
     
    <meta http-equiv="X-UA-Compatible" content="IE=Edge" />
     
     
     
    <asp:ContentPlaceHolder ID="HeadContent" runat="server">
     
     
     
    </asp:ContentPlaceHolder>
     
     
     
    </head>
     
     
     
    <body>
     
     
     
    <form id="form1" runat="server">
     
     
     
    <asp:ScriptManager ID="MasterScriptManager" runat="server" />
     
     
     
    <div>
     
     
     
    <asp:ContentPlaceHolder id="PageTitle" runat="server">
     
     
     
    </asp:ContentPlaceHolder>
     
     
     
    </div>
     
     
     
    </form>
     
     
     
    </body>
     
     
     
    </html>

     

    <%@ Page Title="" Language="C#" MasterPageFile="~/NFL_Teams.master" AutoEventWireup="true" CodeFile="NFL_Teams.aspx.cs" Inherits="NFL_Teams" %>
     
    <%@ Register Assembly="Telerik.Web.UI" Namespace="Telerik.Web.UI" TagPrefix="telerik" %>
      
    <asp:Content ID="Content1" ContentPlaceHolderID="HeadContent" Runat="Server">
    </asp:Content>
    <asp:Content ID="Content2" ContentPlaceHolderID="PageTitle" Runat="Server">
        <telerik:RadListBox ID="lbNFL_Teams" runat="server" DataTextField="TeamDesc" Width="400px" Height="300px" DataSortField="TeamID" OnReordered="lbNFL_Teams_Reordered"
            DataValueField="TeamID" AppendDataBoundItems="true" AutoPostBack="false" CausesValidation="false" AllowTransferOnDoubleClick="true" OnTransferred="lbNFL_Teams_Transferred"
            SelectionMode="Multiple" AllowTransfer="true" TransferToID="lbNFL_Teams_Assigned" AutoPostBackOnTransfer="true"
            AllowReorder="true" AutoPostBackOnReorder="true" EnableDragAndDrop="true" TabIndex="24" ButtonSettings-ShowReorder="false"
            ButtonSettings-ShowTransfer="false" ButtonSettings-ShowTransferAll="false" style="font-family: Arial; font-size: small;">
        </telerik:RadListBox>
     
        <telerik:RadListBox ID="lbNFL_Teams_Assigned" runat="server" DataTextField="TeamDesc" Width="400px" Height="300px" OnTransferred="lbNFL_Teams_Assigned_Transferred"
            DataValueField="TeamID" AppendDataBoundItems="true" AutoPostBack="false" CausesValidation="false" AllowTransferOnDoubleClick="true"
            SelectionMode="Multiple" AllowTransfer="true" TransferToID="lbNFL_Teams" AutoPostBackOnTransfer="true"
            AllowReorder="true" AutoPostBackOnReorder="true" EnableDragAndDrop="true" TabIndex="25" ButtonSettings-ShowReorder="false"
            ButtonSettings-ShowTransfer="false" ButtonSettings-ShowTransferAll="false" style="font-family: Arial; font-size: small;">
        </telerik:RadListBox>
    </asp:Content>

     

    using System;
    using System.Collections;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Web.UI;
    using System.Web.UI.WebControls;
    using Telerik.Web.UI;
     
    public partial class NFL_Teams : System.Web.UI.Page
    {
        public static List<int> gStatuses = new List<int>();
        int intStatus = 0;
        protected void Page_Load(object sender, EventArgs e)
        {
            TeamsManager tm = new TeamsManager();
     
            if (!Page.IsPostBack)
            {
                lbNFL_Teams.Items.Clear();
                lbNFL_Teams.DataSource = tm.GetTeams();
                lbNFL_Teams.DataBind();
            }
     
            if (lbNFL_Teams.Items.Count > 0)
                intStatus = Convert.ToInt32(lbNFL_Teams.Items[0].Value);
            else
                intStatus = 0;
        }
     
        protected void lbNFL_Teams_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
        {
            TeamsManager tm = new TeamsManager();
            Teams Team = new Teams();
            SortListBoxItems(ref lbNFL_Teams, true);
     
            gStatuses.Clear();
            foreach (RadListBoxItem li in lbNFL_Teams_Assigned.Items)
            {
                Team = tm.GetIndividualTeam(li.Text);
                gStatuses.Add(Team.TeamID);
            }
        }
     
        protected void lbNFL_Teams_Assigned_Transferred(object sender, Telerik.Web.UI.RadListBoxTransferredEventArgs e)
        {
            TeamsManager tm = new TeamsManager();
            Teams Team = new Teams();
            Boolean blnFinal = false;
     
            foreach (RadListBoxItem li in lbNFL_Teams_Assigned.Items)
            {
                Team = tm.GetIndividualTeam(li.Text);
     
                if (Team.TeamDesc == "FINAL")
                    blnFinal = true;
     
            }
     
            if (intStatus == 1 && blnFinal == true)
            {
                blnFinal = false;
     
                foreach (RadListBoxItem li in lbNFL_Teams_Assigned.Items)
                {
                    Team = tm.GetIndividualTeam(li.Text);
     
                    if (gStatuses.Contains(Team.TeamID))
                    {
                        RadListBoxItem itemToRemove = lbNFL_Teams_Assigned.FindItemByText(Team.TeamDesc);
                        lbNFL_Teams.Items.Remove(itemToRemove);
                        gStatuses.Remove(Team.TeamID);
                    }
                }
            }
            else
            {
                gStatuses.Clear();
                foreach (RadListBoxItem li in lbNFL_Teams_Assigned.Items)
                {
                    Team = tm.GetIndividualTeam(li.Text);
                    gStatuses.Add(Team.TeamID);
                }
            }
        }
     
     
        private void SortListBoxItems(ref RadListBox rlb, bool pByValue)
        {
            SortedList lListItems = new SortedList();
     
            foreach(RadListBoxItem li in rlb.Items)
            {
                if (pByValue) lListItems.Add(li.Value, li);
                else lListItems.Add(li.Text, li);
            }
     
            rlb.Items.Clear();
     
     
            //add sorted items to listbox
            for (int i = 0; i < lListItems.Count; i++)
            {
                rlb.Items.Add((RadListBoxItem)lListItems[lListItems.GetKey(i)]);
            }
        }
     
        protected void lbNFL_Teams_Reordered(object sender, RadListBoxEventArgs e)
        {
            TeamsManager tm = new TeamsManager();
            Teams Team = new Teams();
            SortListBoxItems(ref lbNFL_Teams, true);
     
            gStatuses.Clear();
            foreach (RadListBoxItem li in lbNFL_Teams_Assigned.Items)
            {
                Team = tm.GetIndividualTeam(li.Text);
                gStatuses.Add(Team.TeamID);
            }
        }
    }

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    /// <summary>
    /// Summary description for TeamsManager
    /// </summary>
    public class TeamsManager
    {
        public TeamCollection GetTeams()
        {
            return new TeamsDB().GetTeams();
        }
     
        public Teams GetIndividualTeam(string TeamDesc)
        {
            return new TeamsDB().GetIndividualTeam(TeamDesc);
        }
    }

     

    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
     
    /// <summary>
    /// Summary description for BusinessBase
    /// </summary>
    public class BusinessBase<T> : List<T>
    {
        public void Sort(IComparer<T> comparer)
        {
            if (comparer == null)
                throw new ArgumentNullException("comparer", "Comparer is null.");
     
            List<T> list = this as List<T>;
            if (list == null)
                return;
     
            list.Sort(comparer);
        }
     
        public System.Data.DataTable ToDataTable<R>()
        {
            IList<R> collection = (IList<R>)this;
            System.Data.DataTable dt = CreateTable<R>();
            Type type = typeof(T);
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(type);
            foreach (R item in collection)
            {
                System.Data.DataRow row = dt.NewRow();
                foreach (System.ComponentModel.PropertyDescriptor prop in properties)
                    row[prop.Name] = prop.GetValue(item);
     
                dt.Rows.Add(row);
            }
            return dt;
        }
     
        private System.Data.DataTable CreateTable<R>()
        {
            Type type = typeof(R);
            System.Data.DataTable dt = new System.Data.DataTable(type.Name);
            System.ComponentModel.PropertyDescriptorCollection properties = System.ComponentModel.TypeDescriptor.GetProperties(type);
     
            foreach (System.ComponentModel.PropertyDescriptor prop in properties)
                dt.Columns.Add(prop.Name, prop.PropertyType);
     
            return dt;
        }
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Web;
    using System.Text;
     
    /// <summary>
    /// Summary description for Teams
    /// </summary>
    public class Teams
    {
        public Teams()
        {
            TeamID = 0;
            TeamDesc = string.Empty;
            TeamConference = string.Empty;
            TeamDivision = string.Empty;
        }
     
        public int TeamID { get; set; }
     
        public string TeamDesc { get; set; }
     
        public string TeamConference { get; set; }
     
        public string TeamDivision { get; set; }
    }
     
    public class TeamCollection: BusinessBase<Teams>
    {
    }
    using System;
    using System.Collections.Generic;
    using System.Linq;
    using System.Text;
    using System.Data;
     
    using Microsoft.SqlServer.Server;
    using System.Data.SqlClient;
    using System.Data.SqlTypes;
     
    /// <summary>
    /// Summary description for TeamsDB
    /// </summary>
    internal class TeamsDB
    {
        public TeamCollection GetTeams()
        {
            TeamCollection uCollection = new TeamCollection();
            Teams Team = new Teams();
     
            Team.TeamID = 1;
            Team.TeamDesc = "FINAL";
            Team.TeamConference = "FINAL";
            Team.TeamDivision = "FINAL";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 2;
            Team.TeamDesc = "Baltimore Ravens";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 3;
            Team.TeamDesc = "Cincinnati Bengals";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 4;
            Team.TeamDesc = "Cleveland Browns";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 5;
            Team.TeamDesc = "Pittsburgh Steelers";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 6;
            Team.TeamDesc = "Buffalo Bills";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 7;
            Team.TeamDesc = "Miami Dolphins";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 8;
            Team.TeamDesc = "New England Patroits";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 9;
            Team.TeamDesc = "New York Jets";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 10;
            Team.TeamDesc = "Houston Texans";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 11;
            Team.TeamDesc = "Indianapolis Colts";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 12;
            Team.TeamDesc = "Jacksonville Jaguars";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 13;
            Team.TeamDesc = "Tennessee Titans";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 14;
            Team.TeamDesc = "Denver Broncos";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 15;
            Team.TeamDesc = "Kansas City Cheifs";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 16;
            Team.TeamDesc = "Los Angeles Chargers";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 17;
            Team.TeamDesc = "Las Vegas Raiders";
            Team.TeamConference = "AFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 18;
            Team.TeamDesc = "Chicago Bears";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 19;
            Team.TeamDesc = "Detroit Lions";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 20;
            Team.TeamDesc = "Green Bay Packers";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 21;
            Team.TeamDesc = "Minnesota Vikings";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "NORTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 22;
            Team.TeamDesc = "Dallas Cowboys";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 23;
            Team.TeamDesc = "New York Giants";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 24;
            Team.TeamDesc = "Philadelphia Eagles";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 25;
            Team.TeamDesc = "Washington Redskins";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "EAST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 26;
            Team.TeamDesc = "Atlanta Falcans";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 27;
            Team.TeamDesc = "Carolina Panthers";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 28;
            Team.TeamDesc = "New Orleans Saints";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 29;
            Team.TeamDesc = "Tampa Bay Buccaneers";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "SOUTH";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 30;
            Team.TeamDesc = "Arizona Cardinals";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 31;
            Team.TeamDesc = "Los Angeles Rams";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 32;
            Team.TeamDesc = "San Fransico 49ers";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            Team.TeamID = 33;
            Team.TeamDesc = "Seattle Seahawks";
            Team.TeamConference = "NFC";
            Team.TeamDivision = "WEST";
            uCollection.Add(FillTeams(Team));
     
            return uCollection;
        }
     
        public Teams GetIndividualTeam(string TeamDesc)
        {
            Teams Team = new Teams();
     
            switch (TeamDesc)
            {
                case "FINAL":
                    Team.TeamID = 1;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "FINAL";
                    Team.TeamDivision = "FINAL";
                    break;
                case "Baltimore Ravens":
                    Team.TeamID = 2;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Cincinnati Bengals":
                    Team.TeamID = 3;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Cleveland Browns":
                    Team.TeamID = 4;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Pittsburgh Steelers":
                    Team.TeamID = 5;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Buffalo Bills":
                    Team.TeamID = 6;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "Miami Dolphins":
                    Team.TeamID = 7;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "New England Patroits":
                    Team.TeamID = 8;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "New York Jets":
                    Team.TeamID = 9;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "Houston Texans":
                    Team.TeamID = 10;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Indianapolis Colts":
                    Team.TeamID = 11;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Jacksonville Jaguars":
                    Team.TeamID = 12;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Tennessee Titans":
                    Team.TeamID = 13;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Denver Broncos":
                    Team.TeamID = 14;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Kansas City Cheifs":
                    Team.TeamID = 15;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Los Angeles Chargers":
                    Team.TeamID = 16;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Las Vegas Raiders":
                    Team.TeamID = 17;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "AFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Chicago Bears":
                    Team.TeamID = 18;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Detroit Lions":
                    Team.TeamID = 19;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Green Bay Packers":
                    Team.TeamID = 20;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Minnesota Vikings":
                    Team.TeamID = 21;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "NORTH";
                    break;
                case "Dallas Cowboys":
                    Team.TeamID = 22;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "New York Giants":
                    Team.TeamID = 23;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "Philadelphia Eagles":
                    Team.TeamID = 24;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "Washington Redskins":
                    Team.TeamID = 25;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "EAST";
                    break;
                case "Atlanta Falcans":
                    Team.TeamID = 26;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Carolina Panthers":
                    Team.TeamID = 27;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "New Orleans Saints":
                    Team.TeamID = 28;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Tampa Bay Buccaneers":
                    Team.TeamID = 29;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "SOUTH";
                    break;
                case "Arizona Cardinals":
                    Team.TeamID = 30;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Los Angeles Rams":
                    Team.TeamID = 31;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "San Fransico 49ers":
                    Team.TeamID = 32;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "WEST";
                    break;
                case "Seattle Seahawks":
                    Team.TeamID = 33;
                    Team.TeamDesc = TeamDesc;
                    Team.TeamConference = "NFC";
                    Team.TeamDivision = "WEST";
                    break;
            }
            return Team;
        }
     
        private Teams FillTeams(Teams Team)
        {
            Teams tm = new Teams();
            tm.TeamID = Team.TeamID;
            tm.TeamDesc = Team.TeamDesc;
            tm.TeamConference = Team.TeamConference;
            tm.TeamDivision = Team.TeamDivision;
     
            return tm;
        }
    }
  6. Peter Milchev
    Admin
    Peter Milchev avatar
    586 posts

    Posted 28 Feb Link to this post

    Hello Mitch,

    The removing of the items should not be done in the Transferred event. I recommend using the OnTransferring event and then you can call the Items.Clear() method so that you remove all the items before the FINAL item is added to the destination: 

    protected void lbNFL_Teams_Assigned_Transferring(object sender, RadListBoxTransferringEventArgs e)
    {
        bool removeAll = e.Items[0].Text == "FINAL";
        if (removeAll)
        {
            e.DestinationListBox.Items.Clear();
        }
    }


    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
  7. Mitch
    Mitch avatar
    4 posts
    Member since:
    Feb 2019

    Posted 28 Feb in reply to Peter Milchev Link to this post

    Peter,

    Your method works when dragging final to the bottom of the listbox, but when you drag it to the top or middle of Items it throws an error still.  Non-negative number required.
    Parameter name: capacity.

    Any Ideas?

     

    Thanks,

     

  8. Peter Milchev
    Admin
    Peter Milchev avatar
    586 posts

    Posted 05 Mar Link to this post

    Hello Mitch,

    The issue is actually due to the fact that the code changes the items' collection and the internal transferring handler relies on it. 

    Another approach that I have tested and it seems to work is removing the items in the PreRender of the RadListBox instead of in the transfer events: 

    <telerik:RadListBox ID="lbNFL_Teams_Assigned" runat="server" OnPreRender="lbNFL_Teams_Assigned_PreRender" ...>

    protected void lbNFL_Teams_Assigned_PreRender(object sender, EventArgs e)
    {
        var lb = sender as RadListBox;
        var finalItem = lb.FindItemByText("FINAL");
        if (finalItem != null)
        {
            lb.Items.Clear();
            lb.Items.Add(finalItem);
        }
    }

    Regards,
    Peter Milchev
    Progress Telerik
    Get quickly onboarded and successful with your Telerik and/or Kendo UI products with the Virtual Classroom free technical training, available to all active customers. Learn More.
Back to Top