Very common task for SharePoint developers is to create a field that shows up state as an image or color in listview. For example, show high priority as exclamation mark. But SharePoint does not out-of-box functionality for this. So, what you need to do is to develope your own field type that will show an icon in listview. To do it, declare a custom type inherited from simple type like text or interger. Then define a rendering pattern, that will render different images, depending on field value, like following:
<FieldType>
<Field Name="TypeName">RequestPriorityIcon</Field>
<Field Name="ParentType">Integer</Field>
<Field Name="TypeDisplayName">Priority Status Icon</Field>
<Field Name="TypeShortDescription">Request Status Icon</Field>
<Field Name="UserCreatable">FALSE</Field>
<Field Name="ShowInListCreate">FALSE</Field>
<Field Name="ShowInSurveyCreate">FALSE</Field>
<Field Name="ShowInDocumentLibraryCreate">FALSE</Field>
<Field Name="ShowInColumnTemplateCreate">FALSE</Field>
<Field Name="CAMLRendering">TRUE</Field>
<Field Name="FieldTypeClass">
ServiceDesk.WebControls.PriorityStatusIconField, ServiceDesk.WebControls, Version=1.0.0.0, Culture=neutral, PublicKeyToken=52e5ed3841bc67a8
</Field>
<RenderPattern Name="DisplayPattern">
<Switch>
<Expr>
<Column/>
</Expr>
<Case Value="1">
<HTML><![CDATA[<img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="/_layouts/images/ServiceDesk/highpriority.gif"/>]]></HTML>
</Case>
<Case Value="2">
<HTML><![CDATA[<img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="/_layouts/images/ServiceDesk/midpriority.gif"/>]]></HTML>
</Case>
<Case Value="3">
<HTML><![CDATA[<img style="border-right-width: 0px; border-top-width: 0px; border-bottom-width: 0px; border-left-width: 0px;" src="/_layouts/images/ServiceDesk/lowpriority.gif"/>]]></HTML>
</Case>
</Switch>
</RenderPattern>
</FieldType>
can define your own class for field type or use inherited class, because it’s not important for our purpose. If you’re using SharePoint 2010 don’t forget to set CAMLRendering to true, or your RenderPattern will not be applied.
Now, you just need to add code in item event receiver or workflow to set your custom field with integer value, and it will be rendered as image in listview.
