AutoCompleteBox: Change casing on CreateTextBlock

10 posts, 0 answers
  1. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 02 May 2013 Link to this post

    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

  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 07 May 2013 Link to this post

    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.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 07 May 2013 Link to this post

    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 ?
  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 May 2013 Link to this post

    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.
  6. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 10 May 2013 Link to this post

    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

  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 10 May 2013 Link to this post

    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?
  8. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 17 May 2013 Link to this post

    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
  9. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 22 May 2013 Link to this post

    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?
  10. John
    John avatar
    14 posts
    Member since:
    Apr 2013

    Posted 22 May 2013 Link to this post

    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

  11. Peter
    Admin
    Peter avatar
    1148 posts

    Posted 27 May 2013 Link to this post

    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?
Back to Top
UI for WinForms is Visual Studio 2017 Ready