Conditional change of background color and text of datagridviews data cell

This is for the winform vb.net 2008 application. I am returning data from the database and based on some static conditions ... I want to change the background color and text. There is no rowdatabound event in winform ...

hope someone can give some recommendations thanks to shannon

+7
colors winforms cell datagridview
Oct 28 '09 at 19:47
source share
3 answers

I got his job ... in the RowPostPaint event. If i put

 if (my criteria here) Me.dgTableInfo.Rows(e.RowIndex).Cells("ColumnName").Style.BackColor = Color.Red end if 
+4
Oct 28 '09 at 20:29
source share

Remember to also set selectoinBackColor ... otherwise, if your red line changes, but you have selected it, it will look just like everything else.

+1
Nov 04 '09 at 19:15
source share

This works without creating or calling multiple subsets or functions. Seems to work for every instance I need.

 Do While myDataReader.Read() ItemID = Trim(myDataReader.Item("ITEM").ToString()) PAR = myDataReader.Item("PAR").ToString() Returned = myDataReader.Item("RETURNED_AMOUNT") Taken = myDataReader.Item("TAKEN_AMOUNT") OnHand = ((PAR + Returned) - Taken) DataGridViewItemList.Rows.Add(ItemID, PAR, Returned, Taken, OnHand) RI = DataGridViewItemList.Rows.Count - 1 If OnHand <= (PAR / 2) Then DataGridViewItemList.Rows(RI).DefaultCellStyle.BackColor = Color.DarkSalmon Else DataGridViewItemList.Rows(RI).DefaultCellStyle.BackColor = Nothing End If Loop 
+1
Jun 08 '11 at 20:20
source share



All Articles