C1SpellChecker TextBox DataBinding Issue

Posted by: james on 15 July 2022, 12:17 am EST

    • Post Options:
    • Link

    Posted 15 July 2022, 12:17 am EST - Updated 3 October 2022, 10:22 pm EST

    There is an issue with the right click context menu item “Spelling”.

    This issue does not effect the selection of a spelling suggestion.

    In other words, the issue effects the button I have highlighted in Red. The option highlighted in green works all good.

    The issue is only if the TextBox is bound to a BindingSource.

    If you click the “Spelling” button, all changes made to the textbox since load disappear straight away. In other words, the difference between what was bound, and what is currently in the textbox.

    Here are pictures to explain what I mean.

    To mitigate the problem I listen to the TextBox MouseDown event and call BindingSource.EndEdit(), but I do not like this solution as it is prone to error down the track when I use the Spelling Control on another bound text box.

    This does not happen if the TextBox is not bound.

    Is this a known issue?

    Also, is there a way to override the “Spelling” button on the context menu to call CheckControl with “false” for FromCursor instead of true? Because even if the user right clicks on a word at the start of the TextBox and uses that button it will not show the dialog at all if the cursor is currently at the end of the textbox.

  • Posted 18 July 2022, 4:47 am EST

    Hi,

    We have reported the issue to the development team and will let you know as soon as we have an update. [Tracking Id : C1WIN-27749]

    To change the behavior of the “Spelling” context menu item, you can use the ContextMenuCreated event. In the event handler, you can remove the original toolstripitem and add a similar toolstripitem. Then you can handle the click event of the new item to perform your custom function. Please refer to the sample attached that calls the CheckControl method with fromCursor = false.

    Regards

    Avnish

    SpellCheck_Custom.zip

  • Posted 20 July 2022, 1:36 am EST

    that’s great. thank you for the sample.

  • Posted 8 April 2024, 2:19 am EST

    any updates regarding [Tracking Id : C1WIN-27749]

    Thanks

  • Posted 9 April 2024, 11:36 pm EST

    Hello,

    The development team is currently working on this issue. Unfortunately, we do not have a concrete ETA for the fix yet, but we will let you know as soon as we get an update from them.

    Thank you for your patience and cooperation.

    Regards,

    Uttkarsh.

  • Posted 10 April 2024, 8:40 pm EST

    Hi Uttkarsh

    Thanks for the reply. It has been nearly 2 years. I found a workaround for the issue as mentioned above, but was wondering how long bugs (with available workarounds like the one above) take to resolve. As mentioned, the workaround is manual, and needs to be repeated whenever the control is used.

    Kind Regards

    James

  • Posted 11 April 2024, 7:21 am EST

    Hello James,

    We completely understand your concerns regarding the delay in the issue fix and apologize for the inconvenience caused to you. Developers have provided a tentative ETA of 2024v1 Hotfix 1. Rest assured, our developers are actively working on it and will try to fix it as soon as possible.

    In the meantime, if you encounter any further challenges or have any questions, please don’t hesitate to reach out. We’re here to assist you.

    Thank you for your patience and understanding.

    Regards,

    Uttkarsh

  • Posted 11 April 2024, 9:00 pm EST

    Hi Uttkarsh

    Thanks.

    Kind Regards

    James

  • Posted 2 July 2024, 12:14 am EST

    Hello James,

    The developers tried to investigate the issue and found out that the problem was inside MS TextBox.

    To highlight the word that has an error, we are using the HideSelection property of MS TextBox.

    We change it to false (to show selection) before showing the “Spelling“ dialog.

    This property recreates the handle of the MS TextBox control and resets the Text property to the value from BindingSource.

    As a workaround, you can update the value in DataSource for every change to the Text property, which can be done by using this piece of code to setup binding:

    textBox1.DataBindings.Add("Text", bs, "Company", false, DataSourceUpdateMode.OnPropertyChanged);

    instead of :

    textBox1.DataBindings.Add("Text", bs, "Company");

    Please refer to the attached sample for implementation. (see SpellCheck_DataBound_Workaround.zip)

    Regards,

    Uttkarsh.

  • Posted 17 July 2024, 1:37 am EST

    Hi Uttkarsh

    Thanks for the reply - I just checked the Designer.cs file, and it already uses OnPropertyChanged - which is not the default, so I’m not 100% sure why I changed it over to this (maybe for some other reason).

    But I can confirm that you are correct, and it works without removing the new text. I’ve gone ahead and removed the “MouseDown” - EndEdit workaround.

    I guess it is just something to keep in mind whenever using the spell control on a bound textbox that there is an issue that requires binding to be on “PropertyChange”.

    What would be nice is when I extend the spellchecker, that the property which stores the TextBox is accessible, such that upon showing the menu I could check if the TextBox is bound to a binding source, and then call EndEdit. But I can’t seem to find any fields that exposes the TextBox that the spelling control has set. This would automatically handle the issue without having to remember.

    Thanks for the update.

    Kind Regards

    James

  • Posted 18 July 2024, 2:18 am EST

    Hello James,

    What would be nice is when I extend the spellchecker, . . .

    You can simply hide the C1SpellChecker’s SetActiveSpellChecking() methods to get the TextBox (or other Controls) as follows:

    internal class MySpellChecker : C1SpellChecker
    {
        List<Control> ControlsWithActiveSpellChecking;
        public MySpellChecker()
        {
            ControlsWithActiveSpellChecking = new List<Control>();
        }
        public new void SetActiveSpellChecking(TextBoxBase textBox, bool spellChecking)
        {
            ControlsWithActiveSpellChecking.Add(textBox);
            base.SetActiveSpellChecking(textBox, spellChecking);
        }
    }


    Please refer to the attached sample for implementation and let us know if it helps. (see SpellCheck_MySpellChecker.zip)

    Regards,

    Uttkarsh.

  • Posted 18 July 2024, 9:47 pm EST

    Hi Uttkarsh

    That’s a really good idea. Thanks. I’ve gone ahead and done this, but it didn’t work out of the box as you will notice that the spell checker has a method “SetSpellChecking” that is used by the designer (instead of SetActiveSpellChecking, but hidden from the class). So I had to take a slightly different approach (below), and it works well! Thanks for the tip.

    public new void SetSpellChecking(Control control, bool spellChecking)
    {
        if (control == null)
            return;
    
        if (control is TextBoxBase)
        {
            SetActiveSpellChecking(control as TextBoxBase, spellChecking);
        }
        else if (control is ISpellCheckableRichEditor)
        {
            SetActiveSpellChecking(control as ISpellCheckableRichEditor, spellChecking);
        }
        else if (control is WebBrowser)
        {
            SetActiveSpellChecking(control as WebBrowser, spellChecking);
        }
    }
    
    public new void SetActiveSpellChecking(TextBoxBase textBox, bool spellChecking)
    {
        textBoxBasesWithActiveSpellChecking.Add(textBox);
        base.SetActiveSpellChecking(textBox, spellChecking);
    }

    Kind Regards

    James

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels