How to get the text on selectionChanged

4 posts, 0 answers
  1. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 28 Jul 2011 Link to this post

    I have IsReadOnly set to false and I have an event on selectionChanged.
    When selection changed is called, it shows the old value in the textbox though.  In the nonpulblic area of the combo box, editableTextbox.Text shows the correct value.  Any easy way of getting it?
  2. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 02 Aug 2011 Link to this post

    Hi Dan,

    I cannot reproduce this issue, could you please send us some sample code to demonstrate your exact approach? Thanks in advance

    Greetings,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

  3. DevCraft banner
  4. danparker276
    danparker276 avatar
    389 posts
    Member since:
    Aug 2010

    Posted 02 Aug 2011 Link to this post

    It's not that big a deal, I found a way around it, but when I'm using a radcombo box and it's auto completing, but I just want to get the text I've typed in.
    Say, I type I'm looking for blue, I type in 'blu' and it selects blue.  I want to know that only blu was typed in.  I only found that information in the non-public editableTextBox.  I can use reflection to get those attributes, but I was wondering if there was an easier way.  The text value of the radcombobox doesn't get the current value.

            private void myComboBox_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
            {
                         myComboBox.Text  // This is not the value I just keyed in

                                <telerik:RadComboBox x:Name="myComboBox" OpenDropDownOnFocus="False"
                                          Margin="5 0 5 0"      IsReadOnly="False"    LostFocus="rcMatterSubId_LostFocus"
                                        SelectionChanged="myComboBox_SelectionChanged"
                                        ClearSelectionButtonVisibility="Visible" ClearSelectionButtonContent="Clear"
                                        Width="60"  
                                                               
                                        IsEditable="True"  
                            />
  5. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 03 Aug 2011 Link to this post

    Hi Dan,

    SelectionChanged event is fired when the the item is changed, that's why you cannot get the typed text like this.

    I would suggest to bind the Text of the ComboBox to a property in your ViewModel - in this way you can get the text as soon as it's updated:

    <telerik:RadComboBox x:Name="myComboBox" OpenDropDownOnFocus="False" Grid.Row="1"
            Margin="5 0 5 0"      IsReadOnly="False"
            SelectionChanged="myComboBox_SelectionChanged"
            ClearSelectionButtonVisibility="Visible" ClearSelectionButtonContent="Clear"
            Width="60"      
            Text="{Binding ComboBoxText, Mode=TwoWay}"
            IsEditable="True"  />

    the ViewModel:

    public class MyViewModel : ViewModelBase
    {
        private string _comboBoxText;
     
        public string ComboBoxText
        {
            set
            {
                if (value != _comboBoxText)
                {
                    _comboBoxText = value;
                    this.OnPropertyChanged("ComboBoxText");
                }
            }
            get
            {
                return _comboBoxText;
            }
        }
    }

    Hope this approach suits your needs.

    Best wishes,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get now >>

Back to Top