What is the default update source trigger for text entered in RadComboBox when Iseditable is true?

3 posts, 0 answers
  1. Vivek
    Vivek avatar
    33 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    I have created a RadComboBox and bound the data to a Collection of strings. I wanted to add a new item to the list when "New" item in the RadComboxBox is selected. i.e. RadComboBox will be set to editable when "New" item is selected and the entered text has to be add to the existing list only when Enter pressed or LostFocus. Could you help me to achieve this ? 

    XAML code to create the combobox with databinding 
    <telerik:RadComboBox x:Name="SettingsNameList" ToolTip="Settings" Width="100" Height="25" ItemsSource="{Binding SettingsCV}" IsEditable="{Binding AddNewSetname,Mode=TwoWay}" Margin="120,5,550,0" Text="{Binding Path=NewSetName,Mode=TwoWay}" />

    C# code to make the radcombobox editable and read the entered value,

    SettingsCV.CurrentChanged += new EventHandler(SettingsCV_SelectedItemChanged);
     
    private void SettingsCV_SelectedItemChanged(object sender, EventArgs e)
            {
                string item = SettingsCV.CurrentItem as string;
                if (item != null)
                {
                    strDefaultSetName = item;
                    if ("New" == strDefaultSetName)
                    {
                        bEditable = true;
                        AddNewSetname = true;
                        //strNewSetName = "Default";
                                            //Raise property to update the UI
                        NotifyPropertyChanged("AddNewSetname");
                    }
                }
            }

    C# code to add the entered text to Collection

    public string NewSetName
            {
                get
                {
                    return strNewSetName;
                }
                set
                {
                    strNewSetName  = value;
                    strNewSetName.Trim();
                    m_strSettingsCollection.Add(strNewSetName);
                    SettingsCV = new ListCollectionView(m_strSettingsCollection);
                    NotifyPropertyChanged("SettingsCV");
                }
            }

    It would be good if i can set the default text when the combo box is editable.

  2. Vivek
    Vivek avatar
    33 posts
    Member since:
    Oct 2012

    Posted 12 Oct 2012 Link to this post

    Thanks, 
    My code works like a charm. Can you suggest me how to set default value when its editable? 
    I am facing problem while adding entered item to the list i.e. i found duplicate values entered to list even i used binary search on List to find the duplicate values, 

    strNewSetName.Trim();
    if ( null!=strNewSetName && 0 > m_strSettingsCollection.BinarySearch(strNewSetName))
    m_strSettingsCollection.Add(strNewSetName);
    m_strSettingsCollection.Find(
    SettingsCV = new ListCollectionView(m_strSettingsCollection);
    NotifyPropertyChanged("SettingsCV");
  3. UI for WPF is Visual Studio 2017 Ready
  4. Yana
    Admin
    Yana avatar
    4554 posts

    Posted 17 Oct 2012 Link to this post

    Hello Vivek,

    I would suggest to use LostFocus event of RadComboBox in order to achieve the needed approach.
    I have attached a simple example based on your code to demonstrate it.

    Please download the attachment and give it a try.

    Kind regards,
    Yana
    the Telerik team

    Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

Back to Top