-1

I would like to know how to use spellcheck each cell of a datagrid dynamically (not in xaml but in cs) I've already tried something like this, but it doesn't work.

public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid)
    {

        for (int i = 0; i < MyDataGrid.Items.Count; i++)
        {
            for (int j = 0; j < MyDataGrid.Columns.Count; j++)
            {
                System.Windows.Controls.TextBox tb = MyDataGrid.GetCell(i, j).Content as System.Windows.Controls.TextBox;
                tb.SpellCheck.IsEnabled = true;
            }
        }
    }

This method is called like this

SpellCheck(MyDataGrid);

Can someone help me? Thank you in advance

gigi23
  • 1
  • 2

1 Answers1

0

after some research I found a solution (using NetSpell), but it needs to be improved, I am open to any suggestion. Thank you

public static void SpellCheck(System.Windows.Controls.DataGrid MyDataGrid)
    {
        TextBlock content;
        string phrase;
        string[] longtext;
        NetSpell.SpellChecker.Dictionary.WordDictionary oDict = new NetSpell.SpellChecker.Dictionary.WordDictionary();

        oDict.DictionaryFile = "fr-FR.dic";
        oDict.Initialize();
        NetSpell.SpellChecker.Spelling oSpell = new NetSpell.SpellChecker.Spelling();

        oSpell.Dictionary = oDict;
        for (int i = 0; i < MyDataGrid.Items.Count; i++)
        {
            for (int j = 0; j < MyDataGrid.Columns.Count; j++)
            {
                content = MyDataGrid.GetCell(i, j).Content as TextBlock;
                phrase = content.Text;
                longtext = phrase.Split(' ');
                content.Inlines.Clear();
                for (int k = 0; k < longtext.Length; k++)
                {
                    if (!oSpell.TestWord(longtext[k]))
                    {
                        //Word does not exist in dictionary
                        content.Inlines.Add(new Run(longtext[k] + " ") { Foreground = Brushes.Red });
                    }
                    else content.Inlines.Add(new Run(longtext[k] + " "));
                }
            }
        }
    }
gigi23
  • 1
  • 2