mardi 21 avril 2015

How can i change the background cell color after the user edited some text

Going from the previous question i had asked that related to color text change after edit. Now it has been requested that i should not highlight the edited text but change the background color.

This is what i want now.

  1. Load existing file with the data to the DataGridView
  2. After loading, DataGridView will populate data
  3. The user will edit text from any cell
  4. After editing the text,
  5. Background color of the edited cell will change color to red,
  6. Only for the edited cell,

How can i change the background color of the edited cell in the DataGridView ?

This is what i tried by changing the background color of the cell.

   private void Gridview_Output_CellBeginEdit_1(object sender, DataGridViewCellCancelEventArgs e)
    {
            DataGridViewCell cell = Gridview_Output[e.ColumnIndex, e.RowIndex];
            cell.Tag = cell.Value != null ? cell.Value : "";

            if (cell.OwningColumn.Name == "ValueOut")
                cell.Style.BackColor = Color.Yellow;
    }

global

    List<DataGridViewCell> dgvc_List = new List<DataGridViewCell>();

Save button

    private void btnSave_Click(object sender, EventArgs e)
    {
         dgvc_List.Add(cell);
                foreach (DataGridViewCell d in dgvc_List)
                {
                    d.Style.BackColor = Color.White;
                }
                dgvc_List.Clear();
    }

Aucun commentaire:

Enregistrer un commentaire