I have a datagridview associated with data that stores data from a database
I made a function that checks if the date matches the correct time interval
if its correct nothing happens.
otherwise it should change the color of the row / cell to red
I tried a lot of things but nothing works
Here is the method I created:
private void CheckFactTermijn() { for (int i = 0; i < dataGridView1.Rows.Count; i++) { DateTime FactuurDatum = Convert.ToDateTime(dataGridView1.Rows[i].Cells[2].Value.ToString()); int termijn = Convert.ToInt32(dataGridView1.Rows[i].Cells[7].Value.ToString()); DateTime finalDate = FactuurDatum.AddDays((double)termijn); if (finalDate > DateTime.Now) { } else { dataGridView1.Rows[i].DefaultCellStyle.BackColor = Color.Red; } } }
I'm not sure when your code works, but try setting the DataGridView DefaultCellStyle properties in your DGV DataGridView.CellFormatting event .
The MSDN link above is an example of what you are trying to do.
, DGV (, ); DataGridViewCellFormattingEventArgs ColumnIndex, , .
, , , . , . , cellformatting, databindingcomplete, , , . , , datagridview , , . , , Shown(), . , , , , , .
, , / Shown() . msdn, , 3/4 .
MSDN
dataGridView1.Rows [i] .DefaultCellStyle.BackColor = Color.Red;
It is necessary to change bakColor for the entire line. With the exception of cells that have their own .BackColor style .
You can set breakPoint in a sentence to verify this.
Source: https://habr.com/ru/post/1753728/More articles:Factory pattern implementation using ANSI C - cFirefox kerning differently with other browsers (negative spacing between letters in CSS) - csshttps://translate.googleusercontent.com/translate_c?depth=1&pto=aue&rurl=translate.google.com&sl=ru&sp=nmt4&tl=en&u=https://fooobar.com/questions/1753725/why-doesnt-and-defaults-to-objectequals-for-valuetypes&usg=ALkJrhgSHDp64w2OY1WQx13dSg_FOR95OwHow to create all configurations of a Visual Studio 2008 C ++ project on the command line? - c ++Состояние гонки в performTraversals и onConfigurationChanged приводит к неправильной компоновке? - androidMac USB Programming - cExchange of links between objects - referenceHow to authenticate requests from iphone application to web service - authenticationGlDrawArrays crashes with EXC_BAD_ACCESS - iphoneMySQL Delete records from 2 tables - mysqlAll Articles