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

SelectedIndex Change Event of ComboBox do not fire

1 Answer 116 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
atif iqbal
Top achievements
Rank 1
atif iqbal asked on 27 Mar 2010, 01:56 PM
Hi all

I make a multi column combo box and on its selectedindexchange event i am showing some text in the label. My SelectedIndexChange event fires when i select the item using mouse but when i place the cursor in the combo box and change the item's selection using up and down arrow keys them selectedindexchnage event do not fire if i hit enete key then it fires. but i want that to be fire by using arrow keys. My html and c# code is given below:

<telerik:RadScriptManager ID="RadScriptManager1" runat="server">
    </telerik:RadScriptManager>
    <telerik:RadComboBox ID="RadComboBox1" runat="server" Skin="Vista" Height="190px"  
        Width="420px" MarkFirstMatch="true" EnableLoadOnDemand="true"
        HighlightTemplatedItems="true" OnClientItemsRequested="UpdateItemCountField"
        OnDataBound="RadComboBox1_DataBound" OnItemDataBound="RadComboBox1_ItemDataBound"
        OnItemsRequested="RadComboBox1_ItemsRequested"
        ontextchanged="RadComboBox1_TextChanged"
        OnClientKeyPressing="HandkeKeyPress"
        OnSelectedIndexChanged="RadComboBox1_SelectedIndexChanged" AutoPostBack ="true" >
         <HeaderTemplate>
            <ul>
                <li class="col1">Name</li>
                <li class="col2">Number</li>
                <%--<li class="col3">Title</li>--%>
            </ul>
        </HeaderTemplate>
        <ItemTemplate>
            <ul>
                <li class="col1">
                    <%# DataBinder.Eval(Container.DataItem, "Name") %></li>
                <li class="col2">
                    <%# DataBinder.Eval(Container.DataItem, "Number") %></li>
                <%--<li class="col3">
                    <%# DataBinder.Eval(Container.DataItem, "ContactTitle") %></li>--%>
            </ul>
        </ItemTemplate>
        <FooterTemplate>
            A total of
            <asp:Literal runat="server" ID="RadComboItemsCount" />
            items
        </FooterTemplate>
    </telerik:RadComboBox>

and c# code is:

 private DataTable table;
    protected void Page_Load(object sender, EventArgs e)
    {
       
        DoDataBind();
    }   

    public void DoDataBind()
    {
        DataTable dt = CreateData();       
        RadComboBox1.DataSource = dt.DefaultView;
        RadComboBox1.DataBind();

    }
    protected void RadComboBox1_DataBound(object sender, EventArgs e)
    {
    
        ((Literal)RadComboBox1.Footer.FindControl("RadComboItemsCount")).Text = Convert.ToString(RadComboBox1.Items.Count);
    }
    private DataTable CreateData()
    {
        table = new DataTable();
        table.Columns.Add("Name", typeof(string));
        table.Columns.Add("Number", typeof(int));
        table.Rows.Add(new object[] { "one", "1" });
        table.Rows.Add(new object[] { "two", "2" });
        table.Rows.Add(new object[] { "three", "3" });
        table.Rows.Add(new object[] { "four", "4" });
        table.Rows.Add(new object[] { "five", "5" });
        table.Rows.Add(new object[] { "six", "6" });
        return table;
    }
    protected void RadComboBox1_ItemsRequested(object sender, RadComboBoxItemsRequestedEventArgs e)
    {

        DataTable dt = new DataTable();
        dt.Columns.Add("Name", typeof(string));
        dt.Columns.Add("Number", typeof(int));
        DataRow[] foundRows;
        foundRows = table.Select("Name LIKE '" + e.Text + "%'");
        foreach (DataRow dr in foundRows)
        {

            dt.ImportRow(dr);
        }
        RadComboBox1.DataSource = dt;
        RadComboBox1.DataBind();
    }

    protected void RadComboBox1_ItemDataBound(object sender, RadComboBoxItemEventArgs e)
    {
        e.Item.Text = ((DataRowView)e.Item.DataItem)["Name"].ToString() + " (" +((DataRowView)e.Item.DataItem)["Number"].ToString() +")";
        e.Item.Value = ((DataRowView)e.Item.DataItem)["Number"].ToString();
    }

 protected void RadComboBox1_SelectedIndexChanged(object o, RadComboBoxSelectedIndexChangedEventArgs e)
    {
        lbltemp.Text  = "abc";
    }

1 Answer, 1 is accepted

Sort by
0
Simon
Telerik team
answered on 27 Mar 2010, 03:25 PM
Hi atif iqbal,

You can achieve this by handling the KeyPressing event in this way:

function keyPressing(sender, eventArgs) {
    var keyCode = eventArgs.get_domEvent().keyCode;
    if (keyCode == 38 || keyCode == 40) {
        setTimeout(function() {
            var item = sender.get_highlightedItem();
            if (item) item.select();
        }, 0);
    }
}

Sincerely yours,
Simon
the Telerik team

Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items.
Tags
ComboBox
Asked by
atif iqbal
Top achievements
Rank 1
Answers by
Simon
Telerik team
Share this question
or