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

How to get the text on selectionChanged

3 Answers 184 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
danparker276
Top achievements
Rank 2
danparker276 asked on 28 Jul 2011, 05:49 PM
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?

3 Answers, 1 is accepted

Sort by
0
Yana
Telerik team
answered on 02 Aug 2011, 11:05 AM
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 >>

0
danparker276
Top achievements
Rank 2
answered on 02 Aug 2011, 06:21 PM
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"  
                        />
0
Yana
Telerik team
answered on 03 Aug 2011, 02:39 PM
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 >>

Tags
ComboBox
Asked by
danparker276
Top achievements
Rank 2
Answers by
Yana
Telerik team
danparker276
Top achievements
Rank 2
Share this question
or