Hi there,
I'd like to have spellchecking in a selected gridcell, where, when right-clicking a ContextMenu should appear with suggestions. In the code below I attach an UltraSpellChecker to an ActiveCell:
private void UltraGrid_AfterCellActivate(object sender, EventArgs e)
{
customEditor.SpellChecker = ultraSpellChecker;
customEditor.ContextMenuStrip = spellingMenuStrip;
ultraGridActiviteitenEnTaken.ActiveCell.EditorControl = customEditor;
}
The spellchecking seems to work, but the MouseDown event does not fire when I (right)click the ActiveCell. Does someone have a solution to this problem?
Ruud
That closes the circle
Thanks again!
-Ruud-
The EditorControl specified a control that implements IProvidesEmbeddableEditor, which will provide a clone of the editor. You are assigning this on a column, so each individual cell does not have an editor; it is the EditorResolved property that does the work of checking to see if the cell has an editor, use that if so, and if not return the Column's editor.
-Matt
Hi Matt,
Thanks for your suggestion! I have implemented the MouseDown just as you said and it works! I also managed to implement the ContextMenuStrip succesfully, though I don't fully understand why it works. This is how I did it (also for those who want to do the same thing):
ultraGrid.DisplayLayout.Bands[0].Columns[0].EditorControl = customEditor;
((EditorWithText)ultraGrid.DisplayLayout.Bands[0].Columns[0].Editor).TextBox.MouseDown += new MouseEventHandler(CustomEditor_MouseDown);
//A reference to the last clicked error in the rich text box (null if no error was clicked last)
private Error lastClickedError = null;
//Get the error at the point where the user clicked in the rich text box
this.lastClickedError = this.spellChecker.GetErrorAtPoint((object)ultraGrid.ActiveCell.EditorResolved, point);
Define the spellingContexMenu_Popop method:
//Clear the menu items previously added to the context menu
//If the last clicked spot on the rich text box was over an error...
//Add the "Add to Dictionary" menu item
//Add the "Ignore All" menu item
//Add a separator item to the context menu
//If there are no suggestions...
//Add the "no spelling suggestions" menu item and disable it
//Otherwise, if there are suggestions...
else
//Add suggestion menu items to the context menu
The contextMenuIgnoreAll_Click method only contains this.spellChecker.IgnoreAll(this.lastClickedError.CheckedWord); and contextMenuAddToDictionary_Click contains AddWordToUserDictionary(this.lastClickedError.CheckedWord);
contextMenuSuggestion_Click should be:
//Get the menu item that was clicked
//Select the error in the rich text box
//Replace the selected error with the suggestion that was clicked
customEditor.SelectedText = suggestionItem.Text;
Thats it. The part I don't fully understand is the relation between EditorControl and EditorResolved (at least, there seems to be one otherwise the SpellCheck and ContextMenu wouldn't work...).
Come to think of it, I think that the reason that the MouseDown isn't firing is because you're hooking the MouseDown of the control's editor's TextBox; the problem with this is that once you set the EditorControl on the grid, the grid requests a *clone* of the associated editor, so you're not hooked into the TextBox that the grid is using. Try something like:
((EditorWithText)this.ultraGrid1.DisplayLayout.Bands[0].Columns[0].Editor).TextBox.MouseDown += new MouseEventHandler(TextBox_MouseDown);
As an aside, though, the default editor is an EditorWithText, and you can assign the SpellChecker on the column itself, but I don't *think* that you can assign a ContextMenuStrip in the same fashion.
The PerformAction was not ment to invoke a MouseDown event, but only to put the ActiveCell into Edit mode (whereafter I did some mouse clicking myself )
I have implemented the UltraTextEditor in the way you suggested, but still the MouseDown doesn't fire when I click within the ActiveCell [:'(] Within a plain UltraTextEditor it works fine, but not when this TextEditor is coupled to the UltraGrid. I guess this has to do with fact that EditorControl is of type Control whereas UltraTextEditor is more specific... Hence, my problem seems to be more general:
How to couple my MouseDown handler to the ActiveCell, such that when I click within the ActiveCell the event is fired and handled by my handler? I tried to couple my handler to the MouseDown event of the EditorControl but this doesn't work... Important to note: it doesn't have to be an UltraTextEditor; if I can use the default editor I'd be more than glad!
I hope this this 'story' clarifies the problem...