How to: Check Spelling of a Grid Cell
- 2 minutes to read
The following example demonstrates how to check the spelling of a GridControl cell’s content:
- Implement the DXSpellChecker behavior for the GridControl. Refer to the Lesson 3 - Configure Spelling Check in XAML topic for details.
Handle a current GridControl view‘s GridViewBase.ShownEditor event that is raised when the grid cell is activated. Retrieve the active editor and run the spell checker as shown below:
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-check-spelling-of-an-active-grid-cell-t598294.
private void CardView_ShownEditor(object sender, EditorEventArgs e) { var cardView = (sender as CardView); BaseEdit activeEditor = cardView.ActiveEditor; if (SpellChecker.SpellCheckMode == DevExpress.XtraSpellChecker.SpellCheckMode.OnDemand) CheckActiveEditor(activeEditor); } void CheckActiveEditor(BaseEdit activeEditor) { activeEditor.Dispatcher.BeginInvoke(new Action(() => { if (SpellChecker.CanCheck(activeEditor)) SpellChecker.Check(activeEditor); }), DispatcherPriority.Loaded); }
In the SpellChecker.CheckCompleteFormShowing event handler, set the Handled property to true to prevent showing The spelling check is complete dialog box when the grid control’s editor does not contain errors:
Note
A complete sample project is available at https://github.com/DevExpress-Examples/how-to-check-spelling-of-an-active-grid-cell-t598294.
void Checker_CheckCompleteFormShowing(object sender, DevExpress.XtraSpellChecker.FormShowingEventArgs e) { e.Handled = true; }
As a result, the spelling form is invoked when the editor is activated. If the SpellingSettings.CheckAsYouType property is set to true, the misspelled words are highlighted.