List Box selected index change not firing

11 posts, 0 answers
  1. Muthu
    Muthu avatar
    10 posts
    Member since:
    Oct 2010

    Posted 23 Mar 2011 Link to this post

    Hi,
    I'm using telerik Radlistbox (winforms controls)..
    The scenario is,when we select an item in Radlistbox then all the related values for the item should be loaded in the window from db..
    The corresponding code is written in selecteditemchanged event of the list box..
    The Radlistbox is dynamically populated at runtime from db based on the letters we type in as particular textbox(like autocomplete) 
        with the top item selected by default...
    The issue is when we select the items other than the item at the top(which is selected by default) then the 
        selectedindexhange event gets fired, the values are loaded in the window.. But if we click the item at the top(which is 
        selected by default) then the selectedindexhange event doesn't gets fired...
    We tried click,mousedown events but when we use that where ever we click on the Radlistbox the (apart from the iitems especially in the scroll bars) the item at the top is loading..

    pls guide us on this issue(whether any events that we can use or any way to avoid the default selection when using the click event)...
  2. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 23 Mar 2011 Link to this post

    Hello,

    Unless I have misunderstood, I'm not able to replicate your issue. Please can you try the following code (written against the latest Q1 2011 release)

    private void Form1_Load(object sender, EventArgs e)
    {
        this.radListControl1.Items.Add("Item 1");
        this.radListControl1.Items.Add("Item 2");
        this.radListControl1.Items.Add("Item 3");
        this.radListControl1.Items.Add("Item 4");
        this.radListControl1.Items.Add("Item 5");
        this.radListControl1.SelectedItem = this.radListControl1.Items[0];
        this.radListControl1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(radListControl1_SelectedIndexChanged);
    }
    void radListControl1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    {
        MessageBox.Show(this.radListControl1.Items[e.Position].Text);
    }

    Look forward to hearing back from you
    Richard
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Muthu
    Muthu avatar
    10 posts
    Member since:
    Oct 2010

    Posted 24 Mar 2011 Link to this post

    Hi to put my query in simple terms.. selected index changed event not firing on clicking a listboxitem that is already selected/ selected by default...

    Regards,
  5. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 24 Mar 2011 Link to this post

    Hello,

    Please see my sample above and the following one. This will show that the SelectedIndexChanged fires every time the item is changed.

    private void Form1_Load(object sender, EventArgs e)
    {
        this.radListControl1.SelectionMode = SelectionMode.One;
        this.radListControl1.Items.Add("Item 1");
        this.radListControl1.Items.Add("Item 2");
        this.radListControl1.Items.Add("Item 3");
        this.radListControl1.Items.Add("Item 4");
        this.radListControl1.Items.Add("Item 5");
         
        this.radListControl1.SelectedIndexChanged += new Telerik.WinControls.UI.Data.PositionChangedEventHandler(radListControl1_SelectedIndexChanged);
        this.radListControl1.SelectedItem = this.radListControl1.Items[0];
    }
    void radListControl1_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    {
        MessageBox.Show(this.radListControl1.Items[e.Position].Text);
    }

    Please try this sample and if you have further issues, please include a sample that demonstrates your issue.
    Thanks
    Richard
  6. Muthu
    Muthu avatar
    10 posts
    Member since:
    Oct 2010

    Posted 24 Mar 2011 Link to this post

    Hi,
    we tried based on your code snippet.. but it doesnot seem to solve the issue..
    note: my query is regarding listbox and not list control.(but we also tried by changing the control to radlistcontrol and using the suggested eventhandler).

    let me repeat the scenario again:  We are using a Radlistbox, we populate it dynamically at runtime. After getting populated the item at the top gets selected by default. When we click on that top most item we want that item value to be placed in a textbox, for that we wrote some code in the selectedindexchanged event of the listbox. But when we select the item at the top the selectedindexchanged event doesnot gets fired. But if we select other items in the list box(say one item that is not selected by default) then the selectedindexchanged event gets fired. pls let me know why this is happening and what is the solution for it?

    Pls find the sample code for data population in radlistbox
    private void txtOwnerFirstName_TextChanged(object sender, EventArgs e)
            {
                    DataTable dt = cgd.GetOwnerInfoSearch(CommonUtils.Constants.OwnerFirstName, txtOwnerFirstName.Text);
                    if (dt != null && dt.Rows.Count > 0)
                    {
                        radCmbNames.DataSource = dt;
                        radCmbNames.DisplayMember = "NAME";
                        radCmbNames.ValueMember = "Time";
                          
                    }
    }


    Pls find the sample code on selectedindexchanged in listbox
    private void radCmbNames_SelectedIndexChanged(object sender, EventArgs e)
            {
    if (radCmbNames.SelectedItem != null)
                    {
                        DataTable dt = GetData(radCmbNames.SelectedValue.ToString());
                        if (dt.Rows.Count != 0)
                        {
                            foreach (DataRow dr in dt.Rows)
                            {
                                txtEmail.Text = dr["OWNER_EMAIL"].ToString();
                           }
                        }
                    }
    }

    Pls let me know if anything requires clarification
  7. Richard Slade
    Richard Slade avatar
    3000 posts
    Member since:
    May 2009

    Posted 24 Mar 2011 Link to this post

    Hello,

    Apologies, I presumed you meant ListControl as you have posted in the ListControl forum and not the (now obsolete) ListBox forum.
    Unfortunatly, I don't have access to the old control to be able to try this out for you. I would advise though that you upgrade to the latest version of the RadControls in order to take advantage of the newer ListControl and all the other fixes, enhancements and new controls that are available on the Q1 2011 Release.

    As I cannot try this out, I'm unable to offer much advice, though an possible solution may be to register for a click event on each of the items in your ListBox.

    If you need anything further please let me know
    Regards,
    Richard
  8. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 25 Mar 2011 Link to this post

    Hi,

    Thank you for the question.

    As of Q2 2010 RadComboBox and RadListBox (and their respective elements) are obsolete and will be removed in one of our next releases. All issues reported by our customers concerning RadComboBox and RadListBox are addressed in the corresponding successor controls - RadDropDownList and RadListControl.

    Specifically regarding your case, I would suggest that you replace the RadListBox with RadDropDownList.

    I hope this information helps.

    Best wishes,
    Peter
    the Telerik team
  9. Kiran
    Kiran avatar
    6 posts
    Member since:
    Jan 2012

    Posted 20 Mar 2012 Link to this post

    Do the  AutoPostBack="true"  for RadListBox then it will fire  event.

    thanks,
    kiran.

  10. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 04 Aug 2014 Link to this post

    Well, I just updated my TelerikDevTools and the RadListBox is still available, still needed and still not working as advertised.
    I'm using the RadListBoxes to move items around as described in http://demos.telerik.com/aspnet-ajax/listbox/examples/overview/defaultcs.aspx#qsf-demo-source

    But I also need to display information about the single selected item so the user knows if this is the right item to move.  However, the OnSelectedIndexChanged event is not firing.
    <telerik:RadListBox runat="server" ID="AllGroupsRadListBox" Height="200px" Width="200px" AllowTransfer="true" SelectionMode="Single" TransferToID="SharedGroupsRadListBox" OnSelectedIndexChanged="AllGroupsRadListBox_SelectedIndexChanged" />
    <telerik:RadListBox runat="server" ID="SharedGroupsRadListBox" Height="200px" Width="200px" /><br />
    Users in selected group:<br />
    <telerik:RadListBox runat="server" ID="UsersRadListBox" Height="200px" Width="200px" />

    private void FillAllGroups()
    {
    BWGroups allGroups = new BWGroups();
    allGroups.GetAllBWGroups();

    AllGroupsRadListBox.DataTextField = "BWGroupName";
    AllGroupsRadListBox.DataValueField = "BWGroupID";
    AllGroupsRadListBox.DataSource = allGroups.BWGroupList;
    AllGroupsRadListBox.DataBind();
    }

    protected void AllGroupsRadListBox_SelectedIndexChanged(object sender, EventArgs e)
    {
    int parseGroupId = -1; Int32.TryParse(AllGroupsRadListBox.SelectedValue.ToString(), out parseGroupId);
    BWUsers usersInGroup = new BWUsers();

    if(parseGroupId > 0)
    usersInGroup.GetActiveBWUsersByGroupID(parseGroupId);

    UsersRadListBox.DataTextField = "BWGroupName";
    UsersRadListBox.DataValueField = "BWGroupID";
    UsersRadListBox.DataSource = usersInGroup.BWUserList;
    UsersRadListBox.DataBind();
    }

    The event is never fired.
  11. Jeremy
    Jeremy avatar
    29 posts
    Member since:
    Apr 2014

    Posted 04 Aug 2014 in reply to Jeremy Link to this post

    I replaced OnSelectedIndexChanged with OnClientSelectedIndexChanged but now I'm getting a script error on the JS.
  12. Dess
    Admin
    Dess avatar
    1609 posts

    Posted 05 Aug 2014 Link to this post

    Hello Jeremy,

    Thank you for writing.

    It seems that your question is related to RadListBox from the UI for ASP.NET AJAX suite. However, this forum concerns Telerik UI for WinForms. I would kindly ask you to post your question in the appropriate forum, where you can get adequate answer.

    Thank you for your understanding.

    Regards,
    Desislava
    Telerik
     
    Check out Telerik Analytics, the service which allows developers to discover app usage patterns, analyze user data, log exceptions, solve problems and profile application performance at run time. Watch the videos and start improving your app based on facts, not hunches.
     
Back to Top
UI for WinForms is Visual Studio 2017 Ready