private void OnCellValidated(object sender, DataGridViewCellEventArgs dataGridViewCellEventArgs) { int rowIndex = dataGridViewCellEventArgs.RowIndex; int columnIndex = dataGridViewCellEventArgs.ColumnIndex; if (rowIndex == m_dataGridView.Rows.Count - 1) return; object cellValue = m_dataGridView[columnIndex, rowIndex].Value; DataGridViewCell cell = m_dataGridView[columnIndex, rowIndex]; CustomPropertyEventArgs customPropertyEventArgs = null; if (columnIndex == 0) { string propertyName = cellValue.ToString().Trim(); if (m_previousPropertyName != null && m_previousPropertyName != propertyName) { PropertyValue previousPropertyValue = m_newProperties[m_previousPropertyName]; m_newProperties.Remove(m_previousPropertyName); m_newProperties[propertyName] = previousPropertyValue; // prepare event args - name change customPropertyEventArgs = new CustomPropertyEventArgs( propertyName, m_previousPropertyName, previousPropertyValue, previousPropertyValue); m_previousPropertyName = null; } cell.Value = propertyName; } else if (columnIndex == 1) { string propertyName = m_dataGridView[0, rowIndex].Value.ToString(); PropertyValue newPropertyValue = null; if (cellValue == null) { m_newProperties[propertyName] = null; } else { string propertyValue = cellValue.ToString(); int propertyValueInt = 0; float propertyValueFloat = 0.0f; cell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft; if (propertyValue.Trim().Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase)) { cell.Value = m_newProperties[propertyName] = true; newPropertyValue = true; } else if (propertyValue.Trim().Equals(bool.FalseString, StringComparison.CurrentCultureIgnoreCase)) { cell.Value = m_newProperties[propertyName] = false; newPropertyValue = false; } else if (!propertyValue.Contains(',') && int.TryParse(propertyValue.Trim(), out propertyValueInt)) { cell.Value = m_newProperties[propertyName] = propertyValueInt; cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; newPropertyValue = propertyValueInt; } else if (!propertyValue.Contains(',') && float.TryParse(propertyValue.Trim(), out propertyValueFloat)) { cell.Value = m_newProperties[propertyName] = propertyValueFloat; cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; newPropertyValue = propertyValueFloat; } else { cell.Value = m_newProperties[propertyName] = propertyValue; newPropertyValue = propertyValue; } } // prepare event args - value change customPropertyEventArgs = new CustomPropertyEventArgs( propertyName, propertyName, newPropertyValue, m_previousPropertyValue); } if (PropertyChanged != null && customPropertyEventArgs != null) PropertyChanged(this, customPropertyEventArgs); }
private void OnCellValidated(object sender, DataGridViewCellEventArgs dataGridViewCellEventArgs) { int rowIndex = dataGridViewCellEventArgs.RowIndex; int columnIndex = dataGridViewCellEventArgs.ColumnIndex; if (rowIndex == m_dataGridView.Rows.Count - 1) { return; } object cellValue = m_dataGridView[columnIndex, rowIndex].Value; DataGridViewCell cell = m_dataGridView[columnIndex, rowIndex]; CustomPropertyEventArgs customPropertyEventArgs = null; if (columnIndex == 0) { string propertyName = cellValue.ToString().Trim(); if (m_previousPropertyName != null && m_previousPropertyName != propertyName) { PropertyValue previousPropertyValue = m_newProperties[m_previousPropertyName]; m_newProperties.Remove(m_previousPropertyName); m_newProperties[propertyName] = previousPropertyValue; // prepare event args - name change customPropertyEventArgs = new CustomPropertyEventArgs( propertyName, m_previousPropertyName, previousPropertyValue, previousPropertyValue); m_previousPropertyName = null; } cell.Value = propertyName; } else if (columnIndex == 1) { string propertyName = m_dataGridView[0, rowIndex].Value.ToString(); PropertyValue newPropertyValue = null; if (cellValue == null) { m_newProperties[propertyName] = null; } else { string propertyValue = cellValue.ToString(); int propertyValueInt = 0; float propertyValueFloat = 0.0f; cell.Style.Alignment = DataGridViewContentAlignment.MiddleLeft; if (propertyValue.Trim().Equals(bool.TrueString, StringComparison.CurrentCultureIgnoreCase)) { cell.Value = m_newProperties[propertyName] = true; newPropertyValue = true; } else if (propertyValue.Trim().Equals(bool.FalseString, StringComparison.CurrentCultureIgnoreCase)) { cell.Value = m_newProperties[propertyName] = false; newPropertyValue = false; } else if (!propertyValue.Contains(',') && int.TryParse(propertyValue.Trim(), out propertyValueInt)) { cell.Value = m_newProperties[propertyName] = propertyValueInt; cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; newPropertyValue = propertyValueInt; } else if (!propertyValue.Contains(',') && float.TryParse(propertyValue.Trim(), out propertyValueFloat)) { cell.Value = m_newProperties[propertyName] = propertyValueFloat; cell.Style.Alignment = DataGridViewContentAlignment.MiddleRight; newPropertyValue = propertyValueFloat; } else { cell.Value = m_newProperties[propertyName] = propertyValue; newPropertyValue = propertyValue; } } // prepare event args - value change customPropertyEventArgs = new CustomPropertyEventArgs( propertyName, propertyName, newPropertyValue, m_previousPropertyValue); } if (PropertyChanged != null && customPropertyEventArgs != null) { PropertyChanged(this, customPropertyEventArgs); } }
private void OnPropertyChangedOrDeleted(object sender, CustomPropertyEventArgs customPropertyEventArgs) { MarkAsModified(); }