views:

629

answers:

2

Does anyone know how to change the Bordercolor for a Datagridviewcell in c#?

Here's a picture of what I mean:

Picture

Backgroundcolor, Textcolor and Images are no Problem, but I don't know how to realise the Borders.

EDIT: I want to realise this with winforms.

Another problem is the cross in the second Row, but that's for later...

+1  A: 

You'd have to draw the cells yourself to achieve this, using OwnerDraw.

steffenj
it was the CellPainting event
binco
+1  A: 

You can hook up on two events on your datagridview. 'ItemCreated' and 'ItemDatabound' Each will pass you an eventarg that can access your itemtemplate. Within that you can .FindControl("ControlId") or step through the .Controls collections to find the cell. Once you got that cell you can do whatever you want - both bordercolor and the cross. ItemCreated will fire for each drawing (postback) while ItemDatabound only when you databind :)

Per Hornshøj-Schierbeck
this only works for System.Web.UI.WebControls but not for Winforms...
binco