Click here to Skip to main content
15,897,334 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello i have simple problem
If no values in datagrid need to repair my code

Error is:
System.NullReferenceException: 'Object reference not set to an instance of an object.'

System.Windows.Forms.DataGridViewCell.Value.get returned null.


What I have tried:

private void ListDataGridView_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
       {
           foreach (DataGridViewRow row in ListDataGridView.Rows)
           {
               if (String.IsNullOrWhiteSpace(row.Cells["R.b."].Value.ToString()))
               {
                   row.DefaultCellStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#51B3E8");
               }
               else
               {
                   row.DefaultCellStyle.ForeColor = System.Drawing.ColorTranslator.FromHtml("#09ECA6");
               }
           }
       }
Posted
Updated 29-Mar-23 0:06am
Comments
PIEBALDconsult 29-Mar-23 12:23pm    
Don't search the grid, search the backing data.

1 solution

 
Share this answer
 

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



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900