Knowledgebase Home Page  >  RapidSpell Desktop .NET  >  3rd Party Ctrls
Search the Knowledge Base
How do I integrate 'as you type' checking with Janus Systems GridEX control?
https://keyoti.com/kb/Default.aspx?ToDo=view&questId=58&catId=61

Options

Print this page
Email this to a friend

The GridEX control from Janus Systems provides a simple mechanism to enable developers to use their own control as a custom cell editor - therefore we can simply use the Keyoti.RapidSpell.AYTTextBox (or Keyoti.RapidSpell.AYTRichTextBox) control as a cell editor.

The following was derived from Janus's "Tutorial 16".

In the DesignTimeLayout property, set the columns that you wish to use as you type spell checking - eg;

gridEXLayout1.LayoutString = "<GridEXLayoutData><RootTable><Caption>Customers</Caption><Columns Collection=\"tru" +"e\"><Column0 ID=\"CustomerID\"><Caption>CustomerID</Caption><DataMember>CustomerID<" +"/DataMember><EditType>Custom</EditType><Key>CustomerID</Key><Position>0</Positio" +"n></Column0><Column1 ID=\"CompanyName\"><Caption>CompanyName</Caption><DataMember>" +"CompanyName</DataMember><EditType>Custom</EditType><Key>CompanyName</Key>...

NOTE: It is important that columns which will be spell checked are set to Custom edit type.  From Janus; "In the right pane, select "CustomerID" column and change the EditType property to Custom. Setting this property, you will be able to get the InitCustomEdit event every time the user tries to edit a cell in this column.  This means by setting EditType for a column, not only can you select all columns for edit, but you can specify which ones."
 

This will cause the GridEX control to fire events relating to this columns when they are edited, so attach event handlers

//C#

this.gridEX1.EndCustomEdit += new Janus.Windows.GridEX.EndCustomEditEventHandler(this.gridEX1_EndCustomEdit);

this.gridEX1.InitCustomEdit += new Janus.Windows.GridEX.InitCustomEditEventHandler(this.gridEX1_InitCustomEdit);
....

private void gridEX1_InitCustomEdit(object sender, Janus.Windows.GridEX.InitCustomEditEventArgs e)

{

 txtCustom.ReadOnly=false;

 //When the user start edition by pressing a key, the EditChar property holds the char that started the edition. If edition
 //was started because the user clicked in the cell the EditChar
 //returns (char)0

 if(e.EditChar!=(char)0 && !txtCustom.ReadOnly){
  txtCustom.Text = e.EditChar.ToString();
  txtCustom.SelectionStart = txtCustom.Text.Length;
 } else {
  if(e.Value==null) {
   txtCustom.Text = "";
  } else {
   txtCustom.Text = e.Value.ToString();
  }

  txtCustom.SelectionLength = txtCustom.Text.Length;

 }

 //Set the EditControl property to let the GridEX control

 //know which control to position in the cell.

 e.EditControl = txtCustom;

}

private void gridEX1_EndCustomEdit(object sender, Janus.Windows.GridEX.EndCustomEditEventArgs e)
{
 //Compare the original value with the value in the control.
 if(txtCustom.Text.CompareTo(e.Value)!=0)

 {
  //If the value is different, set the DataChanged property to true
  //to indicate the control that it has to update the cell value.
  e.DataChanged = true;
  e.Value = txtCustom.Text;
 }

}

 

'VB.NET

Private Sub gridEX1_InitCustomEdit(ByVal sender As Object, ByVal e As Janus.Windows.GridEX.InitCustomEditEventArgs) Handles gridEX1.InitCustomEdit
 txtCustom.ReadOnly = False
 'When the user start edition by pressing a key, the EditChar
 'property holds the char that started the edition. If edition
 'was started because the user clicked in the cell the EditChar
 'returns (char)0
 If e.EditChar <> Chr(0) AndAlso Not txtCustom.ReadOnly Then
  txtCustom.Text = e.EditChar.ToString()
  txtCustom.SelectionStart = txtCustom.Text.Length
 Else
  If e.Value Is Nothing Then
   txtCustom.Text = ""
  Else
   txtCustom.Text = e.Value.ToString()
  End If
  txtCustom.SelectionLength = txtCustom.Text.Length
 End If
 'Set the EditControl property to let the GridEX control
 'know which control to position in the cell.
 e.EditControl = txtCustom
End Sub

Private Sub gridEX1_EndCustomEdit(ByVal sender As Object, ByVal e As Janus.Windows.GridEX.EndCustomEditEventArgs) Handles gridEX1.EndCustomEdit
    'Compare the original value with the value in the control.
        If txtCustom.Text.CompareTo(e.Value) <> 0 Then
            'If the value is different, set the DataChanged property to true
            'to indicate the control that it has to update the cell value.
            e.DataChanged = True
            e.Value = txtCustom.Text
        End If
End Sub

 

 

 

This will cause the Grid to edit with txtCustom, which we define as

//C#
private Keyoti.RapidSpell.AYTTextBox txtCustom;

'VB.NET
Friend WithEvents txtCustom As Keyoti.RapidSpell.AYTTextBox

 

 

The RapidSpellAsYouType control is added to the form as usual, and configured to spell check txtCustom;

//C#
this.rapidSpellAsYouType1.TextComponent = this.txtCustom;

'VB.NET
Me.RapidSpellAsYouType1.TextComponent = Me.txtCustom

 

In this way the as you type text box will be used as the editor, complete C# and VB.NET projects are attached.


Related Questions:

Attachments: