How to: Check Spelling of a Grid Cell

  • 2 minutes to read

The following example demonstrates how to check the spelling of the Grid Control cell content. We assume that the XtraSpellChecker is placed on the form, the necessary dictionaries are specified and the only problem is to find a way to check the grid cell content.

To do this you should handle the ColumnView.ShownEditor event of the XtraGrid. When it is fired, add a SpellCheck menu item to the cell context menu. When the user selects this menu command, the spell checker begins processing the cell content.

To switch on the SpellCheckMode.AsYouType mode, specify the SpellChecker.SpellCheckMode and call the SpellChecker.Check method beforehand.

The code implementing this solution is shown below.

    // Subscribe to the event
    gridView1.ShownEditor += gridView1_ShownEditor;

    // Load dictionaries.
    // Default dictionaries for US English are shipped with XtraSpellChecker. You can uncomment the code below to use this project's dictionaries instead. 
    //string wordsPath = "Dictionaries\\en_US.dic";
    //string grammarPath = "Dictionaries\\en_US.aff";
    //System.Globalization.CultureInfo culture = new System.Globalization.CultureInfo("en-US");
    //SpellCheckerOpenOfficeDictionary dict = new SpellCheckerOpenOfficeDictionary(wordsPath, grammarPath, culture);

    // Switch to the check-as-you-type mode.
    spellChecker1.SpellCheckMode = SpellCheckMode.AsYouType;
    spellChecker1.CheckAsYouTypeOptions.Color = Color.Magenta;
BaseEdit checkedEditor;
private void gridView1_ShownEditor(object sender, EventArgs e)
    BaseEdit activeEditor = gridView1.ActiveEditor;
    if (activeEditor == null || !spellChecker1.CanCheck(activeEditor))
    spellChecker1.SetShowSpellCheckMenu(gridView1.ActiveEditor, true);
    if (!object.ReferenceEquals(checkedEditor, gridView1.ActiveEditor))
        checkedEditor = gridView1.ActiveEditor;