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

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

2 Answers 200 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Vivek
Top achievements
Rank 2
Vivek asked on 12 Oct 2012, 06:48 AM
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 Answers, 1 is accepted

Sort by
0
Vivek
Top achievements
Rank 2
answered on 12 Oct 2012, 07:03 AM
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");
0
Yana
Telerik team
answered on 17 Oct 2012, 08:25 AM
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.

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