How to perform SpellChecker in WinForms GridGroupingControl?
Spellchecker
The Essential
Grid does not have direct support for SpellChecker. In order to
achieve SpellChecker in Grid, you need to customize the Grid by creating the
custom cell renderer and cell model. Refer to the following article
link to know more about the creating cell renderer and cell model.
How to create the Cell Model and Cell Renderer?
Solution:
In this
article, the SpellChecker component is used to validate the
strings in the cell. Based on the result, the cell text is underlined when the
text is misspelled, since customization for multiple words is not provided. To
know more about the SpellChecker component, you can refer to the following
link: WinForms Spellchecker
Creating
cell renderer and cell model:
C#
public class SpellCheckCellRenderer : GridTextBoxCellRenderer
{
//Using SpellChecker tool.
private SpellChecker spellchecker;
public SpellCheckCellRenderer(GridControlBase grid, GridCellModelBase cellModel) : base(grid, cellModel)
{
spellchecker = new SpellChecker();
}
//To underline the word in cell that is misspelled.
protected override void OnDraw(Graphics g, Rectangle clientRectangle, int rowIndex, int colIndex, GridStyleInfo style)
{
//Validate the cell values.
string check = this.spellchecker.SpellCheck(style.CellValue.ToString());
//Checking whether the result has suggestions.
if(check != "")
{
style.Font.Underline = true;
}
base.OnDraw(g, clientRectangle, rowIndex, colIndex, style);
}
}
public class SpellCheckCellModel : GridTextBoxCellModel
{
///<summary>
///Initializes a new <see cref="SpellCheckCellModel "/>
///</summary>
///<param name="grid">GridModel.</param>
public SpellCheckCellModel(GridModel grid) : base(grid)
{ }
/// <summary>
/// Creates a cell renderer.
/// </summary>
/// <param name="control">GridControlBase</param>
/// <returns>A new <see cref="SpellCheckCellRenderer"/>specific for a <see cref="GridControlBase"/></returns>
public override GridCellRendererBase CreateRenderer(GridControlBase control)
{
return new SpellCheckCellRenderer(control, this);
}
}Public Class SpellCheckCellRenderer
Inherits GridTextBoxCellRenderer
'Using SpellChecker tool.
Private spellchecker As SpellChecker
Public Sub New(ByVal grid As GridControlBase, ByVal cellModel As GridCellModelBase)
MyBase.New(grid, cellModel)
spellchecker = New SpellChecker()
End Sub
'To underline the word in cell that is misspelled.
Protected Overrides Sub OnDraw(ByVal g As Graphics, ByVal clientRectangle As Rectangle, ByVal rowIndex As Integer, ByVal colIndex As Integer, ByVal style As GridStyleInfo)
'Validate the cell values.
Dim check As String = Me.spellchecker.SpellCheck(style.CellValue.ToString())
'Checking whether the result has suggestions.
If check <> "" Then
style.Font.Underline = True
End If
MyBase.OnDraw(g, clientRectangle, rowIndex, colIndex, style)
End Sub
End Class
Public Class SpellCheckCellModel
Inherits GridTextBoxCellModel
'''<summary>
'''Initializes a new <see cref="SpellCheckCellModel"/>
'''</summary>
'''<param name="grid">GridModel.</param>
Public Sub New(ByVal grid As GridModel)
MyBase.New(grid)
End Sub
''' <summary>
''' Creates a cell renderer.
''' </summary>
''' <param name="control">GridControlBase</param>
''' <returns>A new <see cref="SpellCheckCellRenderer"/>specific for a <see cref="GridControlBase"/></returns>
Public Overrides Function CreateRenderer(ByVal control As GridControlBase) As GridCellRendererBase
Return New SpellCheckCellRenderer(control, Me)
End Function
End ClassC#
//Add the Custom Cell Model to Grid.
this.gridGroupingControl1.TableModel.CellModels.Add("SpellCheckCell", new SpellCheckCellModel(this.gridGroupingControl1.TableModel));
//Set the Custom Cell Type.
this.gridGroupingControl1.TableDescriptor.Columns[1].Appearance.AnyRecordFieldCell.CellType = "SpellCheckCell";'Add the Custom Cell Model to Grid.
Me.gridGroupingControl1.TableModel.CellModels.Add("SpellCheckCell", New SpellCheckCellModel(Me.gridGroupingControl1.TableModel))
'Set the Custom Cell Type.
Me.gridGroupingControl1.TableDescriptor.Columns(1).Appearance.AnyRecordFieldCell.CellType = "SpellCheckCell"The screenshot below illustrates the Spellchecker support in the GridGroupingControl:

Figure 1: Output
Samples:
Conclusion
I hope you
enjoyed learning how to perform SpellChecker in GridGroupingControl.
You can refer to WinForms GridGroupingControl feature tour page to know about its other groundbreaking feature representations and WinForms GridGroupingControl documentation and how to quickly get started for configuration specifications. You can also explore our WinForms GridGroupingControl example to understand how to create and manipulate data.
For current customers, you can check out our components from the License and Downloads page. If you are new to Syncfusion, you can try our 30-day free trial to check out our other controls.
If you have any queries or require clarifications, please let us know in the comments section below. You can also contact us through our support forums, Direct-Trac, or feedback portal. We are always happy to assist you!