ComboBox SelectionChangeCommitted Event

10 posts, 0 answers
  1. Sason
    Sason avatar
    32 posts
    Member since:
    Aug 2012

    Posted 11 Jul 2010 Link to this post

    Hi

    are there is event like SelectionChangeCommitted in the rad ComboBox  in win forms ?
    the pwoer of this event is that SelectionChangeCommitted is raised only when the user changes the combo box selection. if you use SelectedIndexChanged or SelectedValueChanged to capture user changes, because those events are also raised when the selection changes programmatically.

  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 14 Jul 2010 Link to this post

    Hello Dror,

    Thank you for contacting us.

    Unfortunately we do not have such a property, but what you can do here is subscribe for the DropDownOpened event, and then in it subscribe for the SelectedIndexChanged event and this is how you can access "changing by user" event:
     
    public Form1()
           {
               InitializeComponent();
               this.radComboBox1.DropDownOpened +=new EventHandler(radComboBox1_DropDownOpened);
           }
           bool subscribed = false;
           private void radComboBox1_DropDownOpened(object sender, EventArgs e)
           {
               if (!subscribed)
               {
                   this.radComboBox1.SelectedIndexChanged += new EventHandler(radComboBox1_SelectedIndexChanged);
                   subscribed = true;
               }
           }
     
           void radComboBox1_SelectedIndexChanged(object sender, EventArgs e)
           {
               this.Text = "My Text";
           }

     I hope this helps. If you have any other questions, do not hesitate to contact us.

    Greetings,
    Stefan
    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
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Jason
    Jason avatar
    11 posts
    Member since:
    May 2008

    Posted 20 Jun 2012 Link to this post

    In this example, wouldn't you want to unsubscribe from the event after the drop down closes, so as to not cause the SelectedIndexChanged event to fire upon a later databind?
  5. Jason
    Jason avatar
    11 posts
    Member since:
    May 2008

    Posted 20 Jun 2012 Link to this post

    Also, is this functionality available in the newer DropDown control?
  6. Jack
    Admin
    Jack avatar
    2335 posts

    Posted 25 Jun 2012 Link to this post

    Hi guys,

    We removed RadComboBox control from our suite and now it is replaced with the RadDropDownList control. We decided that the described functionality is a very specific scenario which can be implemented with custom code and it should not be included in RadDropDownList implementation. I am posting here an updated version of the solution offered by my colleague:
    bool clicked = false;
     
    void list_SelectedIndexChanged(object sender, Telerik.WinControls.UI.Data.PositionChangedEventArgs e)
    {
        if (clicked)
        {
            Console.WriteLine("Selected by User: " + e.Position);
            clicked = false;
        }
        else
        {
            Console.WriteLine("Selected programmatically: " + e.Position);
        }
    }
     
    void list_PopupClosed(object sender, RadPopupClosedEventArgs args)
    {
        clicked = args.CloseReason == RadPopupCloseReason.Mouse;
    }

    I hope it helps.
     
    Kind regards,
    Jack
    the Telerik team
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  7. Francisco
    Francisco avatar
    3 posts
    Member since:
    Apr 2013

    Posted 05 Nov 2015 in reply to Jack Link to this post

    Hi Jack,

    Despite this is an old subject/post, I am trying to implement your solution, but, what if I need both previous and new values?

    I remember there was something like:

    e.OldIndex and e.NewIndex

    But now I can't find them withing PositionChangedEventArgs.

    Any clue? (I would not like to use a variable to explicitly get index every time it changes)

    Thanks in advanced.

    Francisco

     

     

     

  8. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 06 Nov 2015 Link to this post

    Hello Francisco,

    If you do not want to use a variable, then you can use the SelectedIndexChanging event. At the time it triggers, the control will hold the old SelectedIndex, and the event will provide the new one:
    void radDropDownList1_SelectedIndexChanging(object sender, Telerik.WinControls.UI.Data.PositionChangingCancelEventArgs e)
     {
         int oldIndex = radDropDownList1.SelectedIndex;
         int newIndex = e.Position;
     }

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
  9. Francisco
    Francisco avatar
    3 posts
    Member since:
    Apr 2013

    Posted 11 Nov 2015 in reply to Stefan Link to this post

    Thanks very much Stefan, it works as expected.

    One more question, I am dynamically adding this RadDropDownList, and I need to pre select some default item.
    I am trying with:

    DataView dv = dt.DefaultView;
    dv.RowFilter = "City = 'NYC'";

      

    RadDropDownList ddl = new RadDropDownList();
    ddl.Name = "ddl":
    ddl.DataSource = dv;
    ddl.DisplayMember = "Name";
    ddl.ValueMember = "Id";
     
    RadListDataItem li = ddl.FindItemExact(SomeId, false);
    if (li != null)
    {
          li.Selected = true;
    }

    But it seems that after line ddl.DataSource = dv items count is always 0 even when dv has items.

    I am sorry for take advantage of this post.

    Thanks in advance,

    fco

     

  10. Francisco
    Francisco avatar
    3 posts
    Member since:
    Apr 2013

    Posted 11 Nov 2015 in reply to Francisco Link to this post

    Complementing previous post:

     In fact, after WinForm finish loading, The dropdown (ddl) has items, but none item is selected.

    Thanks,

    fco

  11. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 12 Nov 2015 Link to this post

    Hi Francisco,

    If you execute this code in the form's constructor, the item will not be selected indeed, however, if you move it to Form.Load or a later event, the item will be correctly selected.

    I hope this helps.

    PS. Indeed, it is better to keep just one topic per thread so the forums are easy to navigate. We will appreciate it if you separate the unrelated questions in separate threads. Thanks.

    Regards,
    Stefan
    Telerik
    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 Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready