Click here to Skip to main content
15,880,796 members
Articles / Programming Languages / Visual Basic

FlagColumn Outlook Style

Rate me:
Please Sign up or sign in to vote.
3.82/5 (5 votes)
3 Feb 2007CPOL 36.8K   551   35   3
Creating a DataGridViewFlagColumn in Outlook style.

Sample image

Introduction

The DataGridViewFlagColumn inherits the existing System.Windows.Forms.DataGridViewImageColumn. It paints the backcolor and chooses the image depending on the value you give the cell. In this code, I use a Flag enumeration of four possible values:

VB
Public Enum Flag As Integer
    Blank = 0
    Red = 1
    Blue = 2
    Yellow = 3
End Enum 

If you create more flag icons, you can extend this enumeration. There also is an ErrorIcon supplied: this icon will be drawn if the value of the cell does not match one of the enumeration values.

The code has two classes: DataGridViewFlagColumn with just one member:

VB
Public NotInheritable Class DataGridViewFlagColumn
    Inherits DataGridViewImageColumn

    Public Sub New()
        Me.CellTemplate = New DataGridViewFlagCell
        ...
    End Sub

End Class

In the constructor, I assign the CellTemplate to the second class: DataGridViewFlagCell, which inherits from System.Windows.Forms.DataGridViewImageCell. This class has some basic methods and functions: it retrieves the right icon and the right backcolor, and the Paint method will use them to paint the cells.

This class also provides a different backcolor when the mouse enters/leaves the cell. Have fun!

License

This article, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)


Written By
Software Developer
Belgium Belgium
This member has not yet provided a Biography. Assume it's interesting and varied, and probably something to do with programming.

Comments and Discussions

 
QuestionC# version Pin
Misiu27-Jul-15 5:22
Misiu27-Jul-15 5:22 
Questionno paint flags Pin
farey20003-Apr-13 9:28
farey20003-Apr-13 9:28 
Generalsocket programming C#.net Pin
nagasrinivas24-Feb-08 20:40
nagasrinivas24-Feb-08 20:40 
hi,
this is srinivas here i am using socket programming to send data to a remote computer using clssocket with namespace system.net and it is working well, but when i am sending continuous data in a packet format to one more remote computers there i am facing the problem of mixing status
one packet format is #010211*
other is $010228&&&&1111*
using visual studio 2005 , oracle 10g
when continuously sending the packet data is been mixed
pls help me in solving the problem of mixing data

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.