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

Text selection problem

3 Answers 119 Views
ComboBox
This is a migrated thread and some comments may be shown as answers.
Alain Beaulieu
Top achievements
Rank 1
Alain Beaulieu asked on 30 Mar 2011, 01:40 PM
Hi,

I have a combobox filled with data such as this (GL Accounts):

10000 - GL Account Name Here
11000 - GL Account Name Here
12000 - GL Account Name Here
13000 - GL Account Name Here
14000 - GL Account Name Here
15000 - GL Account Name Here
20000 - GL Account Name Here
...

The combobox has a fixed width that is smaller than the text above, say:

[                            ]

When the combobox gets the focus it auto-selects the text in the textbox, as it should and this is great. But it does it by starting the selection on the first character and ending on the last character, which ends up like this:

[ccount Name Here]

If it started the selection from the last character to the first one, then I would get this:

[10000 - GL Accou]

For me, the important part is the account ID, and it should always be visible in the textbox whether or not the combobox has the focus (unless the user is typing of course).

I have a feeling that this is not possible at this time with this control, but is it a feature that I can request for an eventual update to the Silverlight Controls pack?

Thanks.

Al

3 Answers, 1 is accepted

Sort by
0
Valeri Hristov
Telerik team
answered on 30 Mar 2011, 01:56 PM
Hello Alain,

You could prevent the ComboBox from scrolling to the right by setting the SelectAllTextEvent property to None:
http://www.telerik.com/help/silverlight/radcombobox-how-to-align-to-the-left-the-text-of-the-comboboxitem-when-it-is-too-long2.html

All the best,
Valeri Hristov
the Telerik team
0
Accepted
Justin
Top achievements
Rank 2
answered on 13 May 2011, 04:37 PM
I've worked on this problem Alain and here is the fix. The problem isn't with the RadComboBox itself, it's the TextBox control inside its template that's causing the undesirable behaviour. Unfortunately the text selection functionality in the TextBox has a SelectAll function which selects text from Left to Right forcing the cursor to the end of the text and cannot be changed or overridden. If you generate a Style of the RadComboBox with Blend you will notice a control called PickerTextBox named PART_EditableTextBox, this essentially inherits TextBox. All you need to do is inherit the RadComboBox and overide the OnLostFocus handler to place the cursor back to the start when the focus is lost.
 
Here is the Code for the custom control. The project I created it for was in VB so just use a C# code converter if need in c#.

Imports Telerik.Windows.Controls
  
Public Class ctwRadComboBox
    Inherits RadComboBox
  
    Private PART_EditableTextBox As PickerTextBox
  
    Public Sub New()
        Me.DefaultStyleKey = GetType(ctwRadComboBox)
    End Sub
  
    Public Overrides Sub OnApplyTemplate()
        MyBase.OnApplyTemplate()
  
        PART_EditableTextBox = DirectCast(GetTemplateChild("PART_EditableTextBox"), PickerTextBox)
  
        PART_EditableTextBox.Select(0, 0)
    End Sub
  
    Protected Overrides Sub OnLostFocus(e As RoutedEventArgs)
        PART_EditableTextBox.Select(0, 0)
    End Sub
  
End Class

Be sure to add a copy of the RadComboBox default style to your Generic.xaml file containing your default style of the new Control and replace all RadComboBox TargetTypes by ctwRadComBox or any class name of your choosing. Or you can simply remove DefaultStyleKey in the Constructor and let RadComboBox draw the control. Hope this helps.

Mark me as answered if it works :).
0
laxman
Top achievements
Rank 1
answered on 22 Sep 2011, 09:18 PM
It didn't worked...I want to show the text selected once the drop down gets close.
Tags
ComboBox
Asked by
Alain Beaulieu
Top achievements
Rank 1
Answers by
Valeri Hristov
Telerik team
Justin
Top achievements
Rank 2
laxman
Top achievements
Rank 1
Share this question
or