Creating custom field types in SharePoint 2007

Good references for creating custom field types

1. http://msdn.microsoft.com/en-us/magazine/dd727508.aspx
2. http://vspug.com/nicksevens/2007/08/31/create-custom-field-types-for-sharepoint/

Troubleshooting :


Issue :  After deploying your custom field type , if you try creating a column in a list , you see below error :

The given key was not present in the dictionary.   at System.ThrowHelper.ThrowKeyNotFoundException() 
   at System.Collections.Generic.Dictionary`2.get_Item(TKey key) 
   at Microsoft.SharePoint.SPFieldCollection.CreateSPField(Int32 index) 
   at Microsoft.SharePoint.SPFieldCollection.EnsureSPField(Int32 index) 
   at Microsoft.SharePoint.SPFieldCollection.get_Item(Int32 iIndex) 
   at Microsoft.SharePoint.ApplicationPages.FieldCustomizationPage.OnPreRender(EventArgs e) 
   at Microsoft.SharePoint.ApplicationPages.FieldNewPage.OnPreRender(EventArgs e) 
   at System.Web.UI.Control.PreRenderRecursiveInternal() 
   at System.Web.UI.Page.ProcessRequestMain(Boolean includeStagesBeforeAsyncPoint, Boolean includeStagesAfterAsyncPoint) 

Resolution :  Follow the below steps :

Go the  settings page of the list in which you are trying to create the column. If you see any entry as shown in the below screen ,  go ahead and delete the Garbage field. 
If you have deployed any custom field type earlier and removed its references later ,  these garbage fields get  attached with that list


Issue

Failed to set value of the "add" column on the "<Your column>" field type control.  See details in log. Exception message: Unable to cast object of type 'System.String' to type 'Microsoft.SharePoint.SPFieldMultiColumnValue'.

Resolution :

If you try to edit the list items created using custom field types , you might see the above error.
To fix this error , set the control's values in the CreateChildControls method as below :

if (ControlMode == Microsoft.SharePoint.WebControls.SPControlMode.Edit)
            {
                txtUserInput = (TextBox)TemplateContainer.FindControl("txtUserInput");
            }