public void UdListItemPasteRowCommand() { try { UdListItemColumnMetaDataList.Sort(delegate(ColumnMetaData c1, ColumnMetaData c2) { return(c1.Order.CompareTo(c2.Order)); }); char[] rowSplitter = { '\r', '\n' }; char[] columnSplitter = { '\t' }; //get the text from clipboard IDataObject dataInClipboard = Clipboard.GetDataObject(); string stringInClipboard = (string)dataInClipboard.GetData(DataFormats.Text); //split it into rows... string[] rowsInClipboard = stringInClipboard.Split(rowSplitter, StringSplitOptions.RemoveEmptyEntries); foreach (string row in rowsInClipboard) { NewUdListItemCommand(""); //this will generate a new udList and set it as the selected udList... //split row into cell values string[] valuesInRow = row.Split(columnSplitter); int i = 0; foreach (string columnValue in valuesInRow) { SelectedUdListItem.SetPropertyValue(UdListItemColumnMetaDataList[i].Name, columnValue); i++; } } } catch (Exception ex) { NotifyMessage(ex.InnerException.ToString()); } }
private void SelectedUdListItem_PropertyChanged(object sender, PropertyChangedEventArgs e) { //IsSelected and IsExpanded are not to be persisted we will igore them... if (e.PropertyName == "IsSelected" || e.PropertyName == "IsExpanded" || e.PropertyName == "IsValid" || e.PropertyName == "NotValidMessage" || e.PropertyName == "LastModifiedBy" || e.PropertyName == "LastModifiedByDate") { return; } object propertyChangedValue = SelectedUdListItem.GetPropertyValue(e.PropertyName); object prevPropertyValue = SelectedUdListItemMirror.GetPropertyValue(e.PropertyName); string propertyType = SelectedUdListItem.GetPropertyType(e.PropertyName); //in some instances the value is not really changing but yet it still is tripping property change.. //This will ensure that the field has physically been modified... //As well when we revert back it constitutes a property change but they will be = and it will bypass the logic... bool objectsAreEqual; if (propertyChangedValue == null) { if (prevPropertyValue == null)//both values are null { objectsAreEqual = true; } else//only one value is null { objectsAreEqual = false; } } else { if (prevPropertyValue == null)//only one value is null { objectsAreEqual = false; } else //both values are not null use .Equals... { objectsAreEqual = propertyChangedValue.Equals(prevPropertyValue); } } if (!objectsAreEqual) { //Here we do property change validation if false is returned we will reset the value //Back to its mirrored value and return out of the property change w/o updating the repository... if (UdListItemPropertyChangeIsValid(e.PropertyName, propertyChangedValue, prevPropertyValue, propertyType)) { Update(SelectedUdListItem); //set the mirrored objects field... SelectedUdListItemMirror.SetPropertyValue(e.PropertyName, propertyChangedValue); SelectedUdListItemMirror.IsValid = SelectedUdListItem.IsValid; SelectedUdListItemMirror.IsExpanded = SelectedUdListItem.IsExpanded; SelectedUdListItemMirror.NotValidMessage = SelectedUdListItem.NotValidMessage; } else {//revert back to its previous value... SelectedUdListItem.SetPropertyValue(e.PropertyName, prevPropertyValue); SelectedUdListItem.IsValid = SelectedUdListItemMirror.IsValid; SelectedUdListItem.IsExpanded = SelectedUdListItemMirror.IsExpanded; SelectedUdListItem.NotValidMessage = SelectedUdListItemMirror.NotValidMessage; return; } } }