Insert words in combobox text - Edit mode

9 posts, 0 answers
  1. Ahmad
    Ahmad avatar
    27 posts
    Member since:
    May 2015

    Posted 29 Mar Link to this post

    Hi,
    I have a RadCombobox with following properties:

    IsEditable="True"
    OpenDropDownOnFocus="False"
    TextSearchMode="Contains"
    IsFilteringEnabled="True"
    UpdateTextOnLostFocus="False"
    CanAutocompleteSelectItems="False"
    IsReadOnly="False"

    And when user types, I open the dropdown with following code:
    comboBox.IsDropDownOpen = true;

    my problem is:
    when a user wants to insert some words in exist text, whole text will be clear.
    what I can do to solve this.

    My project:
    http://www.mediafire.com/file/2ru22za4ztsuas4/ComboBoxEditModeProj.rar

    Thanks.
  2. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    498 posts

    Posted 03 Apr Link to this post

    Hi Ahmad,

    You can try changing the logic of opening the DropDown to execute after the text is already entered. For example, in the Loaded event of the control:

    private void comboBox_Loaded(object sender, RoutedEventArgs e)
        {
            (sender as RadComboBox).ChildrenOfType<TextBox>().FirstOrDefault().TextChanged += MainWindow_TextChanged;
        }
     
        private void MainWindow_TextChanged(object sender, TextChangedEventArgs e)
        {
            if (!this.comboBox.IsDropDownOpen)
                this.comboBox.IsDropDownOpen = true;
        }

    It seems to work in the sample you have provided. Please give it a try.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  3. Ahmad
    Ahmad avatar
    27 posts
    Member since:
    May 2015

    Posted 04 Apr in reply to Stefan Nenchev Link to this post

    Hi Stefan,
    thanks for answer
    I used your solution but it makes another problem:
    when I insert a word, whole text will select and I can't type another word after that.
  4. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    498 posts

    Posted 07 Apr Link to this post

    Hello,

    You can try saving the caretPosition and set it when the DropDown is Opened:

               int caretPosition;
            private void MainWindow_TextChanged(object sender, TextChangedEventArgs e)
            {
                caretPosition = (sender as TextBox).CaretIndex;
                if (!this.comboBox.IsDropDownOpen)
                    this.comboBox.IsDropDownOpen = true;
            }
     
            private void comboBox_DropDownOpened(object sender, EventArgs e)
            {
                (sender as RadComboBox).ChildrenOfType<TextBox>().FirstOrDefault().CaretIndex = caretPosition;
                caretPosition = 0;
            }


    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  5. Ahmad
    Ahmad avatar
    27 posts
    Member since:
    May 2015

    Posted 08 Apr Link to this post

    Hi Stefan,
    thanks
    It was helpful,
    but it is useless when user wanna select a substring and change that.
    there is any way for that?
  6. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    498 posts

    Posted 12 Apr Link to this post

    Hi Ahmad,

    Modifying a substring works fine for me. Please provide steps to reproduce the undesired behavior. I have attached the modified sample.

    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  7. Ahmad
    Ahmad avatar
    27 posts
    Member since:
    May 2015

    Posted 19 Apr Link to this post

    Hi,
    there is an issue:
    I set IsReadOnly to True.
    when I wanna type a word, the first letter will be ignored.
    how I fixed that? 
  8. Stefan Nenchev
    Admin
    Stefan Nenchev avatar
    498 posts

    Posted 24 Apr Link to this post

    Hello Ahmad,

    I am not sure what you mean as when you set the RadComboBox as ReadOnly - you should not be able to type in any letters. What do you mean by "the first letter will be ignored"? It seems that after the custom logic we have introduced, in some cases, it is possible to type in letters even though the control is in ReadOnly mode. Please try subscribing to the PreviewKeyDown event and do the following:

    private void comboBox_PreviewKeyDown(object sender, KeyEventArgs e)
           {
               var comboBox = sender as RadComboBox;
               if (comboBox != null && comboBox.IsReadOnly == true)
               {
                   e.Handled = true;
               }
           }


    Regards,
    Stefan Nenchev
    Telerik by Progress
    Want to extend the target reach of your WPF applications, leveraging iOS, Android, and UWP? Try UI for Xamarin, a suite of polished and feature-rich components for the Xamarin framework, which allow you to write beautiful native mobile apps using a single shared C# codebase.
  9. Ahmad
    Ahmad avatar
    27 posts
    Member since:
    May 2015

    Posted 26 Apr in reply to Stefan Nenchev Link to this post

    Hello Stefan,

    with follwing config:
    IsEditable="True"
    OpenDropDownOnFocus="False"
    TextSearchMode="Contains"
    IsFilteringEnabled="True"
    UpdateTextOnLostFocus="False"
    CanAutocompleteSelectItems="False"
    IsReadOnly="True"

    in your solution, we can't type. but I wanna be able of typing.
    it is my scenario: 
    assume I wanna type "Alex"
    I type "A" ComboBox.Text will be "A"
    but when I type "l"
    ComboBox.Tex will be "l" instead of "Al"


    and there is another problem:
    I can't change a substring in this mode(IsReadOnly="True").

    Thanks.
Back to Top