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 following topic for details: Lesson 3 - Configure Spelling Check in XAML.
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:
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:
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.