multiple selected items with SelectionMode="Single"

9 posts, 1 answers
  1. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 29 Oct 2009 Link to this post

    Hi,

    I have a RadListBox to which I add items using client-side code.
    The RadListBox has default SelectionMode, which is "Single".
    After I add an item I want that item to be selected.
    What happens is that the newly added item is indeed selected but any other already selected item remains selected resulting in multiple selected items which should ot happen. I even explicitly call clearSelection() prior to selecting the newly added item.

    Here is a code smaple:
    <html xmlns="http://www.w3.org/1999/xhtml" > 
    <head runat="server"
        <title></title
    </head> 
    <body> 
        <form id="form1" runat="server"
        <asp:ScriptManager ID="ScriptManager1" runat="server" /> 
         
        <div style="height:300px; width:200px; float:left;"
            <telerik:RadListBox ID="RadListBox1" runat="server" Height="100%" Width="100%" SelectionMode="Single"
                <Items> 
                    <telerik:RadListBoxItem Text="bla" /> 
                    <telerik:RadListBoxItem Text="lala" /> 
                    <telerik:RadListBoxItem Text="qwerty" /> 
                </Items> 
            </telerik:RadListBox> 
        </div> 
        <div style="float:left;"
            <asp:Button ID="Button2" runat="server" Text="Add" OnClientClick="Add(); return false;" /> 
        </div> 
        </form> 
         
        <script type="text/javascript"
            function Add() { 
                var rbl = $find("<%= RadListBox1.ClientID %>"); 
                var item = new Telerik.Web.UI.RadListBoxItem(); 
                item.set_text('pomptidom'); 
                rbl.get_items().insert(0, item); 
                rbl.clearSelection(); 
                item.select(); 
            } 
        </script> 
    </body> 
    </html> 

    Am I doing something wrong? Or is it incorrect behaviour of the RadListBox?

    Regards,

    Mink



  2. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 04 Nov 2009 Link to this post

    Hello Mink,

    This is clearly a bug in the RadListBox. I have logged it into our bug tracking System and I suppose we will fix it in the upcoming weeks. I have updated your telerik points for pointing the issue to us.

    As a temporary workaround move the clearSelection invocation right after the call to the  $find function.

    var rbl = $find("<%= RadListBox1.ClientID %>");
                rbl.clearSelection();


    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.
  3. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 05 Nov 2009 Link to this post

    Don't take this the wrong way, but I'm actually glad it is a bug. :-)
    When you guys (and girls) have fixed it I'll be able to use the RadListBox as easy as I wanted to.

    For now my problem is not solved by your proposal to move the call to clearSelection() because things don't happen as simple in my actual application. There the new item is definately added before I get the chance to switch the selection to it (that's why I want to clear all other selections because if I don't do that I have two selected items (at least visually) eventhough the selection mode is single, which sounds somewhat buggy in itself...).

    So right now I go through all items with javascript and change their className to 'rlbItem' before I set the new item to be selected. I hope this does not mess up some internal administration of selected items for the RadListBox. It did seem to work properly, but now a colleague noticed that in some situations there are no selected items (visually at least) instead of one. I'll look into that.
    But do you have any other ideas how to tackle this for now? (Remember, the way the application is build something like clearSelection() must come after the new item is added.)

    Regards,

    Mink
  4. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 05 Nov 2009 Link to this post

    I have solved my problem and I hope it will help you fix the bug.

    The thing is that in my actual application I don't simply add an item to the RadListBox but that I insert it at position 0.
    I didn't do it this way in the little application I wrote to show my problem because I thought it was just a cosmetic difference whether the new item is placed at the top or at the bottom. But I now figured out that placing the new item at the top, or for that matter anywhere but at the bottom, messes with the internal administration of the selected item(s).
    The property _selectedIndices is not updated when an item is inserted which causes (some of) these indices to be one off.
    For now I explicitly update _selectedIndices when I insert a new item at position 0 and everything works fine now.

    listBox.get_items().insert(0, item);  
     
    for (var i = 0; i < listBox._selectedIndices.length; i++) {  
        listBox._selectedIndices[i] = parseInt(listBox._selectedIndices[i]) + 1;  

    I'll be looking forward to a fixed version of the RadListBox so that I can remove those lines of code and leave everything to the control again.

    Regards,

    Mink
  5. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 06 Nov 2009 Link to this post

    I just also discovered that when you call listBox.get_items().clear()  listBox._selectedIndices also doesn't get updated.
    So for now I clear _selectedIndices explicitlt after calling get_items().clear().
    So probably every action that can influence _selectedIndices should be looked at. Or _selectedIndices should be ommited entirely and every time information about the selected item is needed the list of selected items should be determined on the spot.

    Regards,

    Mink
  6. Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 12 Nov 2009 Link to this post

    Hi Mink,

    Thank you very much for your feedback and suggestions. We will take them in consideration when fixing the issue. The fix should be available by the end of the next week. I have updated your telerik points for pointing us to this issue.

    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.
  7. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 01 Dec 2009 Link to this post

    Hi Genady ,

    How is the fix coming along?
    I was wondering when I could expect it.

    Regards,

    Mink

  8. Answer
    Genady Sergeev
    Admin
    Genady Sergeev avatar
    1600 posts

    Posted 01 Dec 2009 Link to this post

    Hi Mink,

    You can find the issue fixed with the latest version of our controls. This is Q3 2009.

    Greetings,
    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.
  9. Mink
    Mink avatar
    57 posts
    Member since:
    Apr 2009

    Posted 02 Dec 2009 Link to this post

    Oke, great. Thanks.

Back to Top