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

IsEditable="True" TextChanging Event

1 Answer 54 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Jon
Top achievements
Rank 1
Jon asked on 16 Dec 2008, 10:49 PM
I need to make the RadComboBox IsEditable="True", but I still need to know when the Text property is changed.  Searching the forums it looks like there used to be something like:

            RadComboBoxElement comboBoxElement = ((RadComboBoxElement)lbTier1.RootElement.Children[0]);              
            comboBoxElement.TextChanging += new TextChangingEventHandler(comboBoxElement_TextChanging);   

But this code does not work at all on the Q3 build.  Best I can tell RootElement is not exposed, RadComboBoxElement does not exist and there is no TextChangingEventHandler. 

Am I missing something?

1 Answer, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 17 Dec 2008, 09:42 AM
Hi Jon,

I would strongly recommend using bindings. First, you need a data class that implements INotifyPropertyChanged:

public class Data : INotifyPropertyChanged
{
    private string text;
    public string Text 
    { 
        get { return text; } 
        set 
        { 
            text = value; 
            OnPropertyChanged("Text");
            HandleTextChanged();
        }
    }

    private void HandleTextChanged()
    {
        // Put your Text property changed logic here
        ...
    }

    public event PropertyChangedEventHandler PropertyChanged;
    public void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanged != null)
        {
            PropertyChanged(new PropertyChangedEventArgs(propertyName));
        }
    }
}

And then you could bind the Text property of the data class to the Text property of the ComboBox:
<telerikInput:RadComboBox x:Name="Combo1" Text="{Binding Text, Mode=TwoWay}" />

and in the code-behind of the page:
Combo1.DataContext = new Data();

The INotifyPropertyChanged interface implementation is needed to proper two-way binding to the Text property of the combo.

Generally speaking, the "bindings way" for development is recommended in Silverlight and WPF over the "event handling". In other words, you create a data class that contains the business logic and is independent from the UI, and bind it to the UI, in this case a RadComboBox. You can find more examples demonstrating this technique in my blog posts:
http://blogs.telerik.com/ValeriHristov/Posts.aspx

I hope this helps.

All the best,
Valeri Hristov
the Telerik team

Check out Telerik Trainer, the state of the art learning tool for Telerik products.
Tags
ComboBox
Asked by
Jon
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Share this question
or