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

[Solved] Research item in RadComboBox

6 Answers 166 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Thierry Treunet
Top achievements
Rank 1
Thierry Treunet asked on 01 Dec 2009, 04:59 PM
hello,

I have a multi-columns Radcombobox like  :
<telerik:RadComboBox  Width="556px"  ID="Exp_Code" runat="server" Height="190px" Skin="Sunset" 
                         MarkFirstMatch="true"  EnableLoadOnDemand="true" HighlightTemplatedItems="true" 
                        ItemRequestTimeout="1"  OnItemsRequested="Exp_Code_ItemsRequested" OnItemDataBound="Exp_Code_ItemDataBound" DataSourceID="SqlDataSource1" CollapseDelay="1" ExpandDelay="1">  
                        <HeaderTemplate> 
                            <ul> 
                             <li class="col1">Code</li> 
                             <li class="col2">Nom</li> 
                             <li class="col3">CP</li> 
                             <li class="col4">Ville</li> 
                             <li class="col5">Pays</li> 
                            </ul> 
                        </HeaderTemplate> 
                        <ItemTemplate> 
                            <ul> 
                             <li class="col1"><%# DataBinder.Eval(Container.DataItem, "Tiers") %></li>  
                             <li class="col2"><%# DataBinder.Eval(Container.DataItem, "Nom") %></li>  
                             <li class="col3"><%# DataBinder.Eval(Container.DataItem, "CP") %></li>  
                             <li class="col4"><%# DataBinder.Eval(Container.DataItem, "Ville") %></li>  
                             <li class="col5"><%# DataBinder.Eval(Container.DataItem, "Pays") %></li>  
                            </ul> 
                        </ItemTemplate> 
                <CollapseAnimation Duration="200" Type="OutQuint" /> 
             </telerik:RadComboBox> 

In my function Page_Load(), I have this code :
Exp_Code.Text =  (Tiers + "      ").Substring(0, 12); 

I wish on the function Page_Load(), to go to search the corresponding item text like format in function Exp_Code_ItemDataBound :
protected void Exp_Code_ItemDataBound(object sender, RadComboBoxItemEventArgs e)  
        {  
            e.Item.Text = ((DataRowView)e.Item.DataItem)["Tiers"].ToString() + "        - " + ((DataRowView)e.Item.DataItem)["Nom"].ToString() + " - " + ((DataRowView)e.Item.DataItem)["Ville"].ToString();  
            e.Item.Value = ((DataRowView)e.Item.DataItem)["Tiers"].ToString() + "        - " + ((DataRowView)e.Item.DataItem)["Nom"].ToString() + " - " + ((DataRowView)e.Item.DataItem)["Ville"].ToString();  
        } 
Thank you for your help.

Angélique

6 Answers, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 02 Dec 2009, 09:35 AM
Hi Thierry Treunet,

Can you please elaborate more on your requirement?

Kind regards,
Simon
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
Thierry Treunet
Top achievements
Rank 1
answered on 02 Dec 2009, 10:55 AM
hello,

when I assign a value to the text property of combobox will not find me the item that starts with this value.

I want in the page_load () when I put the text in the combobox I make a MarkFirstMatch

what I am more clear ?

Thanks you for your help

Angélique
0
Simon
Telerik team
answered on 02 Dec 2009, 12:11 PM
Hello Thierry Treunet,

Thank you for clarifying.

You could set SelectedValue of the RadComboBox instead of the Text property to the Value of the Item you want to select.

Alternatively you could use the following method to find the first matching Item and select it then:

private RadComboBoxItem FindItemByText(string text)
{
    foreach (RadComboBoxItem item in Exp_Code.Items)
    if (item.Text.StartsWith(text))
        return item;
}

RadComboBoxItem item = FindItemByText((Tiers + "      ").Substring(0, 12));
item.Selected = true;

Please have in mind that you have to do either of these *after* the DataBind method of the RCB is called, so that Items are populated.

Regards,
Simon
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
Thierry Treunet
Top achievements
Rank 1
answered on 02 Dec 2009, 01:53 PM
Thank you for your response.

By cons I do not understand how to connect the combobox with item RadComboBoxItem selected.

can you help me?
0
Simon
Telerik team
answered on 03 Dec 2009, 07:35 PM
Hi Thierry Treunet,

Please use the attached page as a reference.

I hope it helps.

All the best,
Simon
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
Thierry Treunet
Top achievements
Rank 1
answered on 04 Dec 2009, 09:02 AM

Thank you for your example

I solved my problem

thank you very much for your help and responsiveness

Tags
ComboBox
Asked by
Thierry Treunet
Top achievements
Rank 1
Answers by
Simon
Telerik team
Thierry Treunet
Top achievements
Rank 1
Share this question
or