Version

AddWordToUserDictionary Method

Adds a word to the current UserDictionary.
Syntax
'Declaration
 
Public Function AddWordToUserDictionary( _
   ByVal word As String _
) As Boolean
public bool AddWordToUserDictionary( 
   string word
)

Parameters

word
The word to add to the user dictionary.

Return Value

True if the word was added to the user dictionary; False otherwise.
Exceptions
ExceptionDescription
System.InvalidOperationException The user dictionary has not been set.
Example
This sample shows how to determine if the user has clicked an underlined error in a spell checked rich text box.

Imports Infragistics.Win.UltraWinSpellChecker

'A reference to the last clicked error in the rich text box (Nothing if no error was clicked last)
Private lastClickedError As [Error] = Nothing

Private Sub contextMenuAddToDictionary_Click(ByVal sender As Object, ByVal e As EventArgs)
	'Add the last clicked error to the user dictionary
	Me.ultraSpellChecker1.AddWordToUserDictionary(Me.lastClickedError.CheckedWord)
End Sub

Private Sub contextMenuIgnoreAll_Click(ByVal sender As Object, ByVal e As EventArgs)
	'Ignore all instances of the last clicked error
	Me.ultraSpellChecker1.IgnoreAll(Me.lastClickedError.CheckedWord)
End Sub

Private Sub contextMenuSuggestion_Click(ByVal sender As Object, ByVal e As System.EventArgs)
	'Get the menu item that was clicked
	Dim suggestionItem As MenuItem = sender

	'Select the error in the rich text box
	Me.richTextBox1.Select( _
	 Me.lastClickedError.StartIndex, _
	 Me.lastClickedError.EndIndex - Me.lastClickedError.StartIndex + 1)

	'Replace the selected error with the suggestion that was clicked
	Me.richTextBox1.SelectedText = suggestionItem.Text
End Sub

Private Sub richTextBox1_MouseDown(ByVal sender As Object, ByVal e As MouseEventArgs) Handles richTextBox1.MouseDown
	'Get the error at the point where the user clicked in the rich text box
	Dim point As Point = New Point(e.X, e.Y)
	Me.lastClickedError = Me.ultraSpellChecker1.GetErrorAtPoint(Me.richTextBox1, point)
End Sub

Private Sub spellingContextMenu_Popup(ByVal sender As Object, ByVal e As EventArgs) Handles spellingContextMenu.Popup
	'Clear the menu items previously added to the context menu
	Me.spellingContextMenu.MenuItems.Clear()

	'If the last clicked spot on the rich text box was over an error...
	If (Not Me.lastClickedError Is Nothing) Then

		'If there are no suggestions...
		If (Me.lastClickedError.Suggestions.Count = 0) Then

			'Add the "no spelling suggestions" menu item and disable it
			Dim noSuggestionsItem As MenuItem = Me.spellingContextMenu.MenuItems.Add("(no spelling suggestions)")
			noSuggestionsItem.Enabled = False

		'Otherwise, if there are suggestions...
		Else

			'Add suggestion menu items to the context menu
			Dim i As Integer
			For i = 0 To Me.lastClickedError.Suggestions.Count - 1

				Me.spellingContextMenu.MenuItems.Add( _
				 Me.lastClickedError.Suggestions(i), _
				 New EventHandler(AddressOf Me.contextMenuSuggestion_Click))

			Next
		End If

		'Add a separator item to the context menu
		Me.spellingContextMenu.MenuItems.Add("-")

		'Add the "Add to Dictionary" menu item
		Dim addItem As MenuItem = Me.spellingContextMenu.MenuItems.Add( _
		 "Add to Dictionary", _
		 New EventHandler(AddressOf Me.contextMenuAddToDictionary_Click))

		'Add the "Ignore All" menu item
		Me.spellingContextMenu.MenuItems.Add( _
		 "Ignore All", _
		 New EventHandler(AddressOf Me.contextMenuIgnoreAll_Click))

	End If
End Sub
using System.Windows.Forms;
using Infragistics.Win.UltraWinSpellChecker;

//A reference to the last clicked error in the rich text box (null if no error was clicked last)
private Error lastClickedError = null;

private void contextMenuAddToDictionary_Click(object sender, System.EventArgs e)
{
	//Add the last clicked error to the user dictionary
	this.ultraSpellChecker1.AddWordToUserDictionary( this.lastClickedError.CheckedWord );
}

private void contextMenuIgnoreAll_Click(object sender, System.EventArgs e)
{
	//Ignore all instances of the last clicked error
	this.ultraSpellChecker1.IgnoreAll( this.lastClickedError.CheckedWord );
}

private void contextMenuSuggestion_Click(object sender, System.EventArgs e)
{
	//Get the menu item that was clicked
	MenuItem suggestionItem = (MenuItem)sender;

	//Select the error in the rich text box
	this.richTextBox1.Select(
		this.lastClickedError.StartIndex,
		this.lastClickedError.EndIndex - this.lastClickedError.StartIndex + 1 );

	//Replace the selected error with the suggestion that was clicked
	this.richTextBox1.SelectedText = suggestionItem.Text;
}

private void richTextBox1_MouseDown(object sender, MouseEventArgs e)
{
	//Get the error at the point where the user clicked in the rich text box
	Point point = new Point( e.X, e.Y );
	this.lastClickedError = this.ultraSpellChecker1.GetErrorAtPoint( this.richTextBox1, point );
}

private void spellingContextMenu_Popup(object sender, System.EventArgs e)
{
	//Clear the menu items previously added to the context menu
	this.spellingContextMenu.MenuItems.Clear();

	//If the last clicked spot on the rich text box was over an error...
	if( this.lastClickedError != null )
	{
		//If there are no suggestions...
		if( this.lastClickedError.Suggestions.Count == 0 )
		{
			//Add the "no spelling suggestions" menu item and disable it
			MenuItem noSuggestionsItem = this.spellingContextMenu.MenuItems.Add( "(no spelling suggestions)" );
			noSuggestionsItem.Enabled = false;
		}
		//Otherwise, if there are suggestions...
		else
		{
			//Add suggestion menu items to the context menu
			for( int i = 0; i < this.lastClickedError.Suggestions.Count; i++ )
			{
				this.spellingContextMenu.MenuItems.Add( 
					this.lastClickedError.Suggestions[ i ],
					new EventHandler( this.contextMenuSuggestion_Click ) );
			}
		}

		//Add a separator item to the context menu
		this.spellingContextMenu.MenuItems.Add( "-" );

		//Add the "Add to Dictionary" menu item
		MenuItem addItem = this.spellingContextMenu.MenuItems.Add( 
			"Add to Dictionary", 
			new EventHandler( this.contextMenuAddToDictionary_Click ) );

		//Add the "Ignore All" menu item
		this.spellingContextMenu.MenuItems.Add( 
			"Ignore All",
			new EventHandler( this.contextMenuIgnoreAll_Click ) );
	}
}
Requirements

Target Platforms: Windows 10, Windows 8.1, Windows 8, Windows 7, Windows Server 2012, Windows 7, Windows Vista SP1 or later, Windows XP SP3, Windows Server 2008 (Server Core not supported), Windows Server 2008 R2 (Server Core supported with SP1 or later), Windows Server 2003 SP2

See Also