private void listTextGrid_CellEndEdit(object sender, DataGridViewCellEventArgs e) { try { string id = listTextGrid.Rows[e.RowIndex].Cells["id"].Value.ToString(); string prop = listTextGrid.Columns[e.ColumnIndex].DataPropertyName.ToString(); string newValue = listTextGrid.Rows[e.RowIndex].Cells[e.ColumnIndex].Value.ToString(); StringObject foundStringObject = strings.FirstOrDefault(textObject => textObject.Id == id); if (foundStringObject == null || foundStringObject.Id == null) { MessageBox.Show("Not found!"); return; } foundStringObject.HasChanged = !newValue.Equals(foundStringObject.GetType().GetProperty("Origin" + prop).GetValue(foundStringObject).ToString()); if (foundStringObject.HasChanged) { RefreshGridView(); //listTextGrid.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.FromArgb(183, 85, 1, 100); //listTextGrid.Refresh(); } // Add to string objects // processor.AddOrUpdate(prop, ref strings, foundStringObject); } catch (Exception exception) { MessageBox.Show(Translate("0009", "Lỗi") + ": " + exception.Message); } }
public void AddOrUpdate(string prop, ref SortedBindingList <StringObject> strings, StringObject stringObject) { foreach (StringObject stringItem in strings) { if (stringItem.Id == stringObject.Id) { // SecurityElement.Escape(stringNode.Attributes["text"].InnerText) // No escape value stringItem.SetData(prop, new MixedValue(stringObject.GetType().GetProperty(prop).GetValue(stringObject, null))); return; } } strings.Add(stringObject); }