I want to change ForeColor in a specific DataGridView cell after edit. I try to do this by:
Private Sub dgv_CellEndEdit(sender As Object, e As DataGridViewCellEventArgs) Handles dgv_.CellEndEdit
dgv_.Item(e.RowIndex, e.ColumnIndex).Style.ForeColor = Color.Red
End Sub
but it's not working. What am I doing wrong?
You've got the indexes the wrong way around. When you index the Item
property, it's column first, then row:
dgv_.Item(e.ColumnIndex, e.RowIndex).Style.ForeColor = Color.Red
You may have confused yourself because you do go row before column when you do it this way:
dgv_.Rows(e.RowIndex).Cells(e.ColumnIndex).Style.ForeColor = Color.Red
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.