I made code for a text field in a DataGridView with an event handler.
The problem is that I click on another cell with a different value, the background color of the cell turns black.
for example: I have this data in a DataGridView
1 1000
2 2000
3 2000
when i click on 1000 i went well. after that I press 2000, the back color for the current cell is black. But after that, if I click on another 2000, the back color will turn white again.
So, if the value in the selected cell is changed, this makes black black.
Can anyone help me solve this problem?
This is the code for the text field.
private void dgvSJ_EditingControlShowing(object sender, DataGridViewEditingControlShowingEventArgs e) { if (dgvSJ.CurrentCell.ColumnIndex == 10) { TextBox tx = e.Control as TextBox; tx.TextChanged += new EventHandler(tx_TextChanging); } } void tx_TextChanging(object sender, EventArgs e) { rowIndexCell = dgvSJ.CurrentRow.Index; if (dgvSJ.Rows[rowIndexCell].Cells[10].EditedFormattedValue != null && dgvSJ.CurrentRow.Cells[10].EditedFormattedValue.ToString() != "") { dgvSJ.CurrentRow.Cells[10].Value = string.Format(GlobalVar.PriceFormat, Convert.ToDouble(dgvSJ.CurrentRow.Cells[10].EditedFormattedValue)); ![enter image description here][1] } }
source share