c# - Check if datagridview cell is null or empty -


this question has answer here:

i have change background color of cells , when value string or empty, code have write similar other codes here :

for (int rowindex = 0; rowindex < datagridview1.rowcount; rowindex++)             {              string conte = datagridview1.rows[rowindex].cells[7].value.tostring()  ;                 if (string.isnullorempty(conte))                 {                 // datagridview1.rows[rowindex].cells[7].style.backcolor = color.orange;                 }                 else                  { datagridview1.rows[rowindex].cells[7].style.backcolor = color.orange; }         }  

the dataset complete , show me datagridview populated , show me error: enter image description here

how can fix this?? have way write code?

i iterate through cells using following..

foreach (datagridviewrow dgrow in datagridview1.rows) {     var cell = dgrow.cells[7];     if (cell.value != null)   //check null reference     {         cell.style.backcolor = string.isnullorempty(cell.value.tostring()) ?              color.lightcyan :                color.orange;            } } 

Comments

Popular posts from this blog

cakephp - simple blog with croogo -

How to group boxplot outliers in gnuplot -

bash - Performing variable substitution in a string -