Skip to main content Skip to footer

New CellType for Spread for WinForms - I

Spread 7 for WinForms has introduced two new CellTypes to provide more convenience to it's users

  1. GcTextBoxCellType for pure text cells
  2. GcDateTimeCellType for cell with Date Time format

In this blog, lets talk about GcTextBoxCellType for text cells.

GcTextBoxCellType

You can call this celltype an enhanced version of Spread's already existing TextCellType. With this new GcTextBoxCellType you can almost do everything that you can do with a TextBox in general. Earlier with TextCellType it was not possible to handle CrLf and Tab characters during cut copy or paste but with new GcTextBoxCellType there are two properties to handle these characters during cut , copy and paste i.e. AcceptsCrLf and AcceptsTabChar. Few other important featues of GcTextBoxCellType are:

  1. AlternateText : Using GcTextBoxCelltype you can set the alternate text for GcTextBox. You can set the text for null display in GcTextBox which can be used as a watermark for a blank cell. Everytime the cell become empty the AlternateText for Null is shown. Have a look at the example below:

    
    GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType textcell = new GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType();  
    textcell.AlternateText.Null.ForeColor = System.Drawing.Color.Red;  
    textcell.AlternateText.Null.Text = "This cell is blank";  
    fpSpread1.Sheets[0].Cells[0, 0, 10, 0].CellType = textcell;  
    
    

    It shows the out for these cells as follows: AlternateText

  2. AutoConvert : GcTextBoxCellType has introduced AutoConvert property using which you can automatically convert the entered data to the FormatString set for texts. So this can be used as a mask for text data entered in the GcTextBox cell. For example you may make the settings so that if a user enters data in small letters it should automatically be converted in to capital letters. Have a look at the example below:

    
    GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType textcell = new GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType();  
    textcell.AutoConvert = true;  
    textcell.FormatString = "A";  
    fpSpread1.Sheets[0].Cells[0, 0, 10, 0].CellType = textcell;  
    
    
  3. WrapMode: While TextCellType only allows you to set the MultiLine and WordWrap properties with GcTextBoxCellType you can now go a step further. It allows you to also set the WrapMode i.e. whether you want the wrapping to be done by a character or Word.

    
    GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType textcell = new GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType();  
    textcell.WrapMode = GrapeCity.Win.Spread.InputMan.CellType.WrapMode.WordWrap;  
    textcell.Multiline = true;  
    fpSpread1.Sheets[0].Cells[0, 0, 10, 0].CellType = textcell;  
    
    

    Have a look at the image shown to see cells with WordWrap. WrapMode

  4. MaxLineCount: You can set the maximum number of acceptable lines in GcTextBoxCell using MaxLineCount property. This property is useful in cases where you want to limit the data entry in a cell. You can also set the maximum length unit using MaxLengthUnit property. This property gets or sets whether the maximum number of characters allowed in the control are handled based on bytes, characters, or text elements. So you can set the limit of characters allowed in a cell by setting the MaxLength and MaxLengthUnit properties. Use the following code to set a limit of characters in a cell:

    
    GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType inputcell1 = new GrapeCity.Win.Spread.InputMan.CellType.GcTextBoxCellType();  
    inputcell1.MaxLengthUnit = GrapeCity.Win.Spread.InputMan.CellType.LengthUnit.Char;  
    inputcell1.MaxLength = 10;  
    fpSpread1.Sheets[0].Cells[1, 1].CellType = inputcell1;  
    
    

Please go through our online documentation for GcTextBoxCellType more information on it. Download Sample in C# Download Sample in VB.Net

MESCIUS inc.

comments powered by Disqus