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

AutoCompleteBox: Change casing on CreateTextBlock

9 Answers 140 Views
AutoCompleteBox
This is a migrated thread and some comments may be shown as answers.
John
Top achievements
Rank 1
John asked on 02 May 2013, 07:03 PM
Telerik,

I am trying to auto fix the casing if a tag is being entered that is already in the AutoCompleteItems list.  I am handling the CreateTextBlock event and keep getting an  object reference not set to an instance of an object. error when trying to create the new TokenizedTextBlockElement.

Maybe there is a better way ?

Private Sub RadAutoCompleteBox_CreateTextBlock(sender As Object, e As CreateTextBlockEventArgs)
 
    If TypeOf e.TextBlock Is TokenizedTextBlockElement Then
        For Each item As RadListDataItem In RadAutoCompleteBox1.AutoCompleteItems
            If item.Text.ToLower = e.Text.ToLower Then
                e.TextBlock = New TokenizedTextBlockElement(item.Text)
                Exit For
            End If
        Next
    End If
 
End Sub

9 Answers, 1 is accepted

Sort by
0
Stefan
Telerik team
answered on 07 May 2013, 08:21 AM
Hello John,

Thank you for writing.

I can confirm that the described exception occurs in this case and I logged it in our Public Issue Tracking System. You can add your vote and subscribe for status change alerts at the following link: http://www.telerik.com/support/pits.aspx#/public/winforms/14964.

To work around the issue, please create an instance of the TokenizedTextBlockElement, set its Text and then assign it to the TextBlock:
void radAutoCompleteBox1_CreateTextBlock(object sender, CreateTextBlockEventArgs e)
       {
           if (e.TextBlock is TokenizedTextBlockElement)
           {
               foreach (RadListDataItem item in radAutoCompleteBox1.AutoCompleteItems)
               {
                   if (item.Text.ToLower() == e.Text.ToLower())
                   {
                       TokenizedTextBlockElement element = new TokenizedTextBlockElement();
                       element.ContentElement.Text = item.Text;
                       e.TextBlock = element;
                   }
               }
           }
       }

Your 
Telerik Points have been updated for this report.

Should you have any other questions or suggestions, do not hesitate to contact us.
 

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
John
Top achievements
Rank 1
answered on 07 May 2013, 02:18 PM
Stefan,

Thanks for the reply.  

I have updated my code and still have ran into a problem.  The casing is not changed.  Typing in 'john' when the AutoCompleteItems contains 'John' will still output 'john' visually.

How do I go about fixing this ?
0
Stefan
Telerik team
answered on 10 May 2013, 09:32 AM
Hi John,

From your initial post I could not understand what exactly your goal is. To make the token text lower, you should use the TextBlockFormatting event, not the CreateTextBlock. Here is the code you need:
void radAutoCompleteBox1_TextBlockFormatting(object sender, TextBlockFormattingEventArgs e)
{
    e.TextBlock.Text = e.TextBlock.Text.ToLower();
}

I hope that this will work for you.

Kind regards,
Stefan
the Telerik team
WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
0
John
Top achievements
Rank 1
answered on 10 May 2013, 02:20 PM
Stefan,

Lets see if these pictures help explain the problem better.  If there is anyway that I will not have to wait 3 business days for a response, that would be very helpful.

The code you provided in your first response looks like it should have worked.

Thanks

0
Stefan
Telerik team
answered on 10 May 2013, 03:31 PM
Hello John,

Thank you for writing back and for the additional details. I am not clear with your scenario.

In order to modify the text used to create the TextBlockElements, you will need to override a method in the AutoCompleteBoxViewElement. Once you do that, in order to use the custom AutoCompleteBoxViewElement, you will have to create custom RadAutoCompleteBoxElement and custom RadAutoCompleteBox.

Attached you can find a sample demonstrating that. Please give it a try and let me know how it works for you.

As to the time you are getting replies, please note that the usual time we address forum threads is within 72 hours in business days. If you need an answer in a shorter time frame, you should use the support ticketing system, where your threads will be addressed by the type of the license you have.

I hope that you find this information useful.

Kind regards,
Stefan
the Telerik team
RadChart for WinForms is obsolete. Now what?
0
John
Top achievements
Rank 1
answered on 17 May 2013, 04:00 PM
Stefan,

This is exactly what I was looking for.  There seems to be one problem with the code though.

I am not able to set a theme on the custom control.  I think something needs to be modified so that can happen.

Thanks
0
Stefan
Telerik team
answered on 22 May 2013, 05:36 AM
Hi John,

Can you please try to override the ThemeClassName in the control as follows and see how it will work for you:
public class MyRadAutoCompleteBox : RadAutoCompleteBox
{
    protected override RadTextBoxControlElement CreateTextBoxElement()
    {
        return new MyRadAutoCompleteBoxElement();
    }
 
    public override string ThemeClassName
    {
        get
        {
            return typeof(RadAutoCompleteBox).FullName;
        }
        set
        {
            base.ThemeClassName = value;
        }
    }
 
}

More information about inheriting themes can be found here: http://www.telerik.com/support/kb/winforms/general/inherit-themes-from-radcontrols.aspx.

I hope this helps.
 

Regards,
Stefan
Telerik
RadChart for WinForms is obsolete. Now what?
0
John
Top achievements
Rank 1
answered on 22 May 2013, 01:34 PM
Stefan,

The link you provided, http://www.telerik.com/support/kb/winforms/general/inherit-themes-from-radcontrols.aspx works perfectly with changing the theme for the button project example.  I was able to drop a Windows8 theme onto the form and then Windows8 becomes a choice under the ThemeName property.

However, this is not the case with the AutoCompleteBox.  When I drop the Windows8 theme onto the form, there is no choice under the ThemeName property.  If I manually type "Windows8" in for the ThemeName property then the control is put in an odd state where some elements of the theme are taking place.

Could you please show me this working with your AutoCompleteBox-replace-the-text-used-to-create-a-textblock.zip example?

Thanks

0
Peter
Telerik team
answered on 27 May 2013, 01:01 PM
Hello John,

Thank you for writing.

When I overridden the ThemeClassName property (as we mentioned in the previous thicket) I was able to select the Windows8 theme from the ThemeName property drop-down. Please refer to the attached video for my attempts.

You should restart the Visual Studio after modifying this property. If this does not help please, open a new support ticket and send us your application (or a sample application) that demonstrates the case and I will be glad to help further.

I am looking forward to your reply.

Regards,
Peter
Telerik
RadChart for WinForms is obsolete. Now what?
Tags
AutoCompleteBox
Asked by
John
Top achievements
Rank 1
Answers by
Stefan
Telerik team
John
Top achievements
Rank 1
Peter
Telerik team
Share this question
or