Quantcast
Channel: Windows Forms Data Controls and Databinding forum
Viewing all articles
Browse latest Browse all 2535

Datagridview cell background color proper Cell event ?

$
0
0

Hello,

I am trying to understand difference between CellFormatting and CellPainting event in DatagridView for a scenario where I want to set backgroundcolor of a cell by using some condition regarding CellValue.

I tried both approaches (to format background) in CellFormatting and CellPainting event, and both seems to work fine...

I know what is a general usage of CellFormatting and CellParsing Event, and also i understand that in CellPainting event i can make some drawing of cell, not just set a color, but for my task, is there any difference where should i implement my coloring?

I saw in MSDN article how they use it in Cell formatting event

http://msdn.microsoft.com/en-us/library/system.windows.forms.datagridview.cellformatting(v=vs.110).aspx

If ((stringValue.IndexOf("pink") > -1))Then
                e.CellStyle.BackColor = Color.Pink
End If 

One more thing, maybe worth to mention, my datagridview is bound to my Dataset.Datatable with a bindingSource.

Whenever table data gets changed (by using datagridview control to edit value, or by using a code to update directly some table value), backgroundcolor check condition should be executed.

Thank You very much in advance

Milos


Viewing all articles
Browse latest Browse all 2535

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>