text changed event firing before the selectedvalue changed

7 posts, 0 answers
  1. Roy
    Roy avatar
    6 posts
    Member since:
    Oct 2006

    Posted 16 Feb 2009 Link to this post

    i have a normal radcombobox (not multicolumn), and i populate it using the textchanged event , through a stored proc that searches on text entered,  the stored proc and datalayer returns an custom object collection and it fills the radcomboo correctly. i cannot use the autocomplete mode as the amount of data that will eventually be in the combobox will be very cumbersome, as well as the search is not a simple text search as it searches on more than one column in the Database.
    however now when i select an item in the combobox either by pressing down or by selecting an item with the mouse it then selects that item and puts the text into the radcombo.text field, however it is my understanding that the event that fires this off is the selectedvalue changed? however the text changes and txtchanged is run before selectedvaluechanged  and this is causing problems for me? is this the correct order of events firing and if so how can i get around this ?

    here is sample of similar code
       private void rcboInfo_TextChanged(object sender, EventArgs e) 
            { 
                List<InfoComboDetails> allInfos = controller.GetInfoBySearchString(searchstr); 
                foreach (info i in allInfos) 
                { 
     
                    RadComboBoxItem rcbi = new RadComboBoxItem(i.Column1 + " - " + i.colum2 , i.ID); 
                    rcboInfo.Items.Add(rcbi); 
                } 
                  
            } 
     
     private void rcboInfo_SelectedValueChanged(object sender, EventArgs e) 
     { 
    rcboinfo2.SelectedValue = controller.GetInfo2ByInfoID((int)rcboInfo.SelectedValue).ID; 
     

  2. Roy
    Roy avatar
    6 posts
    Member since:
    Oct 2006

    Posted 17 Feb 2009 Link to this post

    hi i really need some help with this issue , as its quite urgent. i have tried so many different resolutions and have come up empty handed, it appears you cannot populate a radcombobox using the textchanged event and then save the selected value in the selected value changed event concurrently, at the moment it is one or the other which does not serve my purposes.
    please help

  3. UI for WinForms is Visual Studio 2017 Ready
  4. Nick
    Admin
    Nick avatar
    767 posts

    Posted 17 Feb 2009 Link to this post

    Hello Roy,

    In the standard combobox the TextChanged event is fired before the ValueChanged event and in this regard RadCombobox works correctly. Your code is predicated on a wrong assumption and unfortunately it has to be changed. Populating data in TextChanged event is a hack in general and should be avoided. 

    Please extend a bit on your scenario so that we can think of a work-around that actually works for you. As far as I understand, you need to present a subset of all your data at any given moment. Do you think that you can use two comboboxes. When the first subset is selected in the first combobox the second one gets updated? I am looking forward to your reply.

    Sincerely yours,
    Nick
    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.
  5. Roy
    Roy avatar
    6 posts
    Member since:
    Oct 2006

    Posted 17 Feb 2009 Link to this post

    The problem has come about from a requirement to do list item filtering in a RadComboBox; the principle of which is as follows: The RadComboBox is text-editable such that a user may move their carat into the text field portion of the combo box and start to type. As the user types, the list of RadComboBoxItems in its Items collection will update to reflect values appropriate with the user’s input text.

     

    This portion works correctly and a user can type into the box and have the Items collection of the combo box update from the RadComboBox’s TextChanged event. In the code that handle’s this event, all values passed into the event as well as the instantiated RadComboBox and its associated Items collection are traversable and correct. It needs to be stated, however, that this TextChanged event fires twice; first with the correct data being send to the event handler and then, immediately thereafter, a second time with a bunce of blank Strings and null values being passed through. We have coded around this double event firing.

     

    However, a second event is also required that will cater for the user actually making a selection from the list of RadComboBoxItems that are available at the time and such a selection will be made through mouse action on the drop down list presented to them.

     

    We have unsuccessfully attempted to use both the exposed SelectedValueChanged event and the SelectedIndexChanged event handlers for these controls and in both situations the scenario is the same. No matter what is done, the earlier TextChanged event fires (twice, once with garbage) before the SelectedValueChanged event fires. Stepping through the code shows some interesting behaviour in the way in which the event synchronicity is handled; the first TextChanged event fires and executes until a call to a separate method is required, at which point the second event propagates and starts processing. After the second TextChanged event is processed the SelectedValueChanged event is fired (again, twice) and that event will complete execution before the first TextChanges event un-pauses and finally completes.

     

    The problem thus is as follows: TextChanged is an event that is used to rebuild the Items collection and SelectedIndexChanged is an event that is used to populate the rest of the form based on the user’s choice. Simply put, the TextChanges event firing before a SelectedIndexChanged event is causing the collection to be rebuilt and thus causing the RadComboBox control to lose its state and the ever important SelectedValue property that we hope to retrieve there.

  6. Roy
    Roy avatar
    6 posts
    Member since:
    Oct 2006

    Posted 17 Feb 2009 Link to this post

    a basic description of the problem is i have an accout table with a code field and name field  and i need to populate the the combo with both fields and ahve a stored proc that searches on both the code and the name using the search criteria, and whether each of the code or the name starts with the text entered into the text box then refills the combo with the results returned. i cant use the autocomplete mode as that will only search on the code or whichever value is populated first, i have the code + " - " + name populated as the display member and the id populated as the value
  7. Nick
    Admin
    Nick avatar
    767 posts

    Posted 17 Feb 2009 Link to this post

    Hi Roy,

    Thank you for contacting me back.

    Can you avoid rebuilding the combobox items in the following way:

     private void radComboBox1_TextChanged(object sender, EventArgs e) 
            { 
                if (this.radComboBox1.Text.ToLower() == "abc"
                { 
                    this.radComboBox1.Items.Clear(); 
                    RadComboBoxItem rcbi = new RadComboBoxItem(); 
                    rcbi.Text = "New Item"
                    radComboBox1.Items.Add(rcbi); 
                    RadComboBoxItem rcbi2 = new RadComboBoxItem("Second new item"); 
                    radComboBox1.Items.Add(rcbi2); 
                } 
                if (this.radComboBox1.Text.ToLower() == "cba"
                { 
                    this.radComboBox1.Items.Clear(); 
                    RadComboBoxItem rcbi = new RadComboBoxItem(); 
                    rcbi.Text = "New Item 2"
                    radComboBox1.Items.Add(rcbi); 
                    RadComboBoxItem rcbi2 = new RadComboBoxItem("Second new item 2"); 
                    radComboBox1.Items.Add(rcbi2); 
                } 
     
            } 
     
            private void radComboBox1_SelectedIndexChanged(object sender, EventArgs e) 
            { 
                if (this.radComboBox1.SelectedIndex == -1) { 
                    return
                } 
                Console.WriteLine(this.radComboBox1.SelectedIndex); 
                 
            } 
     
            private void radComboBox1_SelectedValueChanged(object sender, EventArgs e) 
            { 
                if (this.radComboBox1.SelectedText == "abc" || 
                    this.radComboBox1.SelectedText == "cba"
                    return
                Console.WriteLine(this.radComboBox1.SelectedText); 
            } 

    I confirm the double firing of events and we are going to address the issue in one of our future releases. I have updated your Telerik points for bringing our attention to this matter.

    Please write me back with comments on the source I gave.

    All the best,
    Nick
    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.
  8. Roy
    Roy avatar
    6 posts
    Member since:
    Oct 2006

    Posted 23 Feb 2009 Link to this post

    Thanks for the help, managed to find a workaround whereby i set the selected index to 0 if the return collection count = 1

    thanks very much

Back to Top
UI for WinForms is Visual Studio 2017 Ready