How to add an indicator to the datagridview

0

What I would like to add in my Weight field that I show you below

A word, that is to say for the values that are in ZERO "0" that in the gridview is visualized as NA and if it has a value different from ZERO, that conserves the value. I do not know if I explain myself. I do not have an intermediate code, to present it, the value is of a decimal type. I await your help. thanks

    
asked by JuanL 07.09.2018 в 00:49
source

1 answer

2

Without knowing how you retrieve your data or how you store it in the datagridView, what I can think of is that you create a method that runs through all the rows you have and compare the value of your column Weight, if this is equal to 0 you replace it with "NA".

Something like that would be:

public void remplazaCero()
{
    foreach (DataGridViewRow dRow in DataGridView1.Rows)
    {
        if (dRow.Cells.Item(2).Value == 0)
            dRow.Cells.Item(2).Value = "NA";
    }
}

2 is the index of the column you are going to compare (start counting from 0)

Finally you send your method calling where you load your DatagridView, it should work.

    
answered by 07.09.2018 / 01:40
source