This is a migrated thread and some comments may be shown as answers.
contains problem
1 Answer 44 Views
This is a migrated thread and some comments may be shown as answers.
Frank
Top achievements
Rank 2
Frank asked on 12 Aug 2009, 08:27 AM
Hi,.

I am about to update an application to use the Radlistbox, where I currently use the ASP.NET Listbox.
I have 2 listboxes, where the 1st contains values, that can be transferred to the 2nd.
- BUT the 2nd has already some preselected, and if the values are in the 2nd listbox, they should NOT be in the 1st Listbox.

VERY simple, and no problem when I use the classic listboxes.
But how is this done in Radlistboxes?

This is quite simple, but I couldn't find the answer in this forum.

See my example script:

HTML:
    <form id="form1" runat="server"
     
     
    <div> 
        <telerik:RadScriptManager ID="RadScriptManager1" Runat="server"
        </telerik:RadScriptManager> 
        hello</div> 
     
     
    <div class="radtxt"
        <div style="float: left;"
            <div> 
                All Websites:</div> 
            <telerik:RadListBox ID="listWebsites" runat="server" Width="180px"  
                Height="200px" TransferToID="listSelectedwebsites" 
                Skin="Telerik" /> 
        </div> 
        <div style="float: left;"
            <div style="vertical-align: middle; text-align: center;"
                <asp:Button ID="btnTransferright" CssClass="specialbuttons" OnClientClick="return transferRight()" 
                    Text="Add >>" runat="server" /> 
            </div> 
            <div> 
                <asp:Button ID="btnTransferleft" CssClass="specialbuttons" OnClientClick="return transferLeft()" 
                    Text="<< Remove" runat="server" /> 
            </div> 
        </div> 
        <div style="float: left;"
            <div> 
                Selected Website(s):</div> 
            <telerik:RadListBox ID="listSelectedwebsites" runat="server" Width="180" Height="200px" 
                Skin="Telerik" /> 
        </div> 
    </div> 
    </form> 

And the VB-script:
 Protected Sub Page_Load(ByVal sender As ObjectByVal e As System.EventArgs) Handles Me.Load 
 
        Me.listSelectedwebsites.Items.Add(New RadListBoxItem("RadListBoxItem1", 1)) 
        'Me.listSelectedwebsites.Items.Add(New RadListBoxItem("RadListBoxItem2", 2)) 
        Me.listSelectedwebsites.Items.Add(New RadListBoxItem("RadListBoxItem3", 3)) 
 
        If Not Me.listSelectedwebsites.Items.Contains(New RadListBoxItem("RadListBoxItem1", 1)) Then 
            Me.listWebsites.Items.Add(New RadListBoxItem("RadListBoxItem11", 11)) 
        End If 
 
        If Not Me.listSelectedwebsites.Items.Contains(New RadListBoxItem("RadListBoxItem2", 2)) Then 
            Me.listWebsites.Items.Add(New RadListBoxItem("RadListBoxItem22", 22)) 
        End If 
 
        If Not Me.listSelectedwebsites.Items.Contains(New RadListBoxItem("RadListBoxItem3", 3)) Then 
            Me.listWebsites.Items.Add(New RadListBoxItem("RadListBoxItem33", 33)) 
        End If 
 
    End Sub 

This VB dos not work:
If Not Me.listSelectedwebsites.Items.Contains(New RadListBoxItem("RadListBoxItem1", 1)) Then
- I want to check if the value is in the 2nd listbox - if not I put it in the 1st listbox.

But I have no luck.

Hope someone can help?

Thanks.

Br
Frank






1 Answer, 1 is accepted

Sort by
0
Genady Sergeev
Telerik team
answered on 12 Aug 2009, 11:46 AM
Hello Frank,

I suggest you to use the FindItem method of the RadListBox to find whether it contains a given item or not. In your case, this would result to:

 
        If RadListBox1.FindItem(Function(a As RadListBoxItem) a.Text = "RadListBoxItem1" And a.Value = 1) IsNot Nothing Then 
            Lbl1.Text = "contains" 
        End If 
  

Unfortunately, the contains method does not work with Items created with new because they are not quite the same as the items currently in the listbox.

Regards,
Genady Sergeev
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.
Asked by
Frank
Top achievements
Rank 2
Answers by
Genady Sergeev
Telerik team
Share this question
or