SelectionChanged Event Clips the Beginning of Long Text

3 posts, 1 answers
  1. Richard
    Richard avatar
    17 posts
    Member since:
    Nov 2008

    Posted 04 Jun 2009 Link to this post

    If a RadComboBoxItem's Content extends past the bounds of the RadComboBox's Width property and that item is selected, the RadComboBox.SelectionChanged event clips the beginning of that long text by placing the inner TextBox.SelectionStart at the very end of the line.

    This could be solved in a number of ways. These are some ideas of mine that came to mind:

    1. Assuming this behavior might be intended for some people, give us a new property where we can toggle between the two behaviors. SelectionChangedCaretStart="True/False" or something to that effect.
    2. Make the RadComboBox's inner TextBox public? At the very least, protected would be sufficient for our needs. Note: even if you made this public, there seems to be some kind of override on the caret placement. I know this because after failing to gain access through reflection, I used the VisualTreeHelper to assign SelectionStart=0 on the SelectionChanged event and debugging revealed that it ran the code fine, but some other event was making the caret go to the end again. The only other way I can think of doing this is to create a new thread that waits a bit until that event is done before changing the caret position back to zero. Granted, if you guys make any changes to the control's structure, this would then crash, so this isn't the most elegant solution by any means.

    • The latest version of Silverlight 2 is installed, version Silverlight 2 GDR 1 (2.0.40115.0).
    • Operating System: Windows Vista Home Premium (32-bit).
    • Attempted Browsers: Internet Explorer 8.0.6001.18702, Mozilla Firefox version 3.0.10, Google Chrome 2.0.172.28.
    • Telerik version: 2009.1.413.1020.
    • Preferred programming language: C#.
    • Microsoft Visual Studio 2008 Professional Edition, Version 9.0.30729.1 SP.
    • Microsoft Expression Blend 2 Service Pack 1, Version 2.1.1760.0.

  2. Answer
    Valeri Hristov
    Admin
    Valeri Hristov avatar
    2252 posts

    Posted 08 Jun 2009 Link to this post

    Hi Alex,

    As a simple workaround for the problem I would suggest the following code, that does not rely on the RadComboBox control template structure:

    <telerikInput:RadComboBox x:Name="combo1" Height="25" Width="100" ItemsSource="{Binding}"
     IsEditable="True" DropDownOpened="combo1_DropDownOpened" DisplayMemberPath="name"
     SelectionChanged="combo1_SelectionChanged" />

    private void ClearComboBoxSelection(RadComboBox combo)
    {
     Dispatcher.BeginInvoke(() =>
     {
      TextBox textBox = combo.ChildrenOfType<TextBox>()[0];
      textBox.SelectionStart = 0;
      textBox.SelectionLength = 0;
     });
    }

    private void combo1_SelectionChanged(object sender, Telerik.Windows.Controls.SelectionChangedEventArgs e)
    {
     ClearComboBoxSelection(combo1);
    }

    private void combo1_DropDownOpened(object sender, EventArgs e)
    {
     ClearComboBoxSelection(combo1);
    }

    I will add the feature request to our database, but having in mind that the current behavior is the same as the standard WPF ComboBox behavior and the workaround above, I cannot promise a date for its implementation.

    Kind regards,

    Valeri Hristov
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. Richard
    Richard avatar
    17 posts
    Member since:
    Nov 2008

    Posted 08 Jun 2009 Link to this post

    This solution is pretty much what I was thinking would have to be done. Fortunately, your previous answer about changing IsEditable="False" fixed this problem as well.

    Again, this works for our scenario, but I could imagine that this would also be useful to some other folks. Put it at the bottom of the list I guess :P

    Thanks again.
Back to Top