Knowledgebase Home Page  >  RapidSpell Desktop .NET  >  Behavior Customization
Search the Knowledge Base
DataGridView and RapidSpellDialog (C#).
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=243&catId=62

Options

Print this page
Email this to a friend

Note: RapidSpellAsYouType supports DataGridView cells beautifully with the DataGridView_AYT_Manager control (see main demo project or help please).

To spell check DataGridView cells with the dialog .net spell checker:

We use a simple wrapper around each cell to make the cells spell checkable (ISpellCheckableTextComponent). The idea is to initialize the RapidSpellDialog each time the spell check button is clicked, by resetting what text boxes it is going to check, and using instances of the wrapper.


C# Code Example

//create text components for all cells of interest

foreach (DataGridViewRow r in dataGridView1.Rows)

{

if (r.Cells[0].ValueType == typeof(string))

rsd.AddTextComponent(new SpellCheckableDataGridCell(r.Cells[0]));

}

First step is to add this class to your project;

 

class SpellCheckableDataGridCell : ISpellCheckableTextComponent

{

int selStart, selLen;

StringBuilder text = new StringBuilder();

public void Dispose()

{

text.Clear();

}

public event EventHandler Disposed;

public bool Enabled

{

get { return true; }

}

public event EventHandler GotFocus;

private DataGridViewCell dataGridViewCell;

public DataGridViewCell DataGridViewCell

{

get { return dataGridViewCell; }

set { dataGridViewCell = value; }

}

public SpellCheckableDataGridCell(DataGridViewCell dataGridViewCell)

{

this.dataGridViewCell = dataGridViewCell;

text = new StringBuilder(dataGridViewCell.Value.ToString());

}

public bool HideSelection

{

get

{

return false;

}

set

{

}

}

public bool ReadOnly

{

get { return false; }

}

public void ScrollToCaret()

{

}

public string SelectedText

{

get

{

return text.ToString(selStart, selLen);

}

set

{

text.Remove(selStart, selLen);

text.Insert(selStart, value);

//update cell

dataGridViewCell.Value = text.ToString();

}

}

public int SelectionLength

{

get

{

return selLen;

}

set

{

selLen = value;

}

}

public int SelectionStart

{

get

{

return selStart;

}

set

{

selStart = value;

}

}

public string Text

{

get

{

return text.ToString();

}

set

{

text.Clear();

text.Append(value);

//update cell

dataGridViewCell.Value = text.ToString();

}

}

}

Assuming RapidSpellDialog exists on the form and is named “rsd”, setup the spell check using this code.

In this example we only take the first column (Cells[0]) but you can iterate as many different columns as you need adding each as well).

void RefreshSpell()

{

rsd.TextBoxBaseToCheck = null;

//add any regular text boxes to be checked

rsd.TextBoxBaseToCheck = richTextBox1;

//create text components for all cells of interest

foreach (DataGridViewRow r in dataGridView1.Rows)

{

if (r.Cells[0].ValueType == typeof(string))

rsd.AddTextComponent(new SpellCheckableDataGridCell(r.Cells[0]));

}

}

and when starting the spell check

private void spellBT_Click(object sender, EventArgs e)

{

RefreshSpell();

rsd.Check();

}

 


Related Questions:

Attachments:

No attachments were found.