CellFormating get curent row

117 Views Asked by At

I am using DataGridView CellFormating to format specified cells. The code I am trying:

 private void dgwPart_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        if (this.arts.Type == ArtType.Pak)
        {
            if (dgwPart.Columns[e.ColumnIndex].Name == "Discount")
                e.Value = "";
        }
    }

The problem is that it changes the value for all column, but I only want that it changes the value for specified row. How do I manage it?

1

There are 1 best solutions below

0
On

You can use e.CurrentCell to find whether it is the row you want, something like:

    If (dvImages.CurrentCell.RowIndex == 10)
    { 
        Debug.WriteLine("Do something")
    }

    If ((int)(dvImages.CurrentCell.Value) = 100)
    {
       ...
    }

* these should be within the cellformat, after you check the column. you may need check the syntax, I just typed this from my header.