How can I do this? I tried setting up a custom Data Filter but it isn't working.
The datatypes in the owner and editor are set to decimal.
public class DecimalInputDataFilter : IEditorDataFilter { private const string DecimalRegexPattern = @"(\-\.?\d{1}|\(\.?\d{1}|\.?\d{1}){1}\d*(\.\d*)?"; public object Convert(EditorDataFilterConvertArgs args) { var cell = args.Context as UltraGridCell; if (cell == null) { args.Handled = false; return null; } var value = cell.Value as decimal?; switch (args.Direction) { case ConversionDirection.DisplayToEditor: return CleanInput(value.ToString()); case ConversionDirection.EditorToDisplay: return value; case ConversionDirection.OwnerToEditor: return value; case ConversionDirection.EditorToOwner: return value; } args.IsValid = false; return null; } public static decimal CleanInput(string input) { if (string.IsNullOrWhiteSpace(input)) return 0m; var match = Regex.Match(input.Replace(",", string.Empty), DecimalRegexPattern).Value; if (string.IsNullOrWhiteSpace(match)) return 0m; var negative = match.StartsWith(@"-") || match.StartsWith(@"("); decimal result; if (negative) { if (decimal.TryParse(match.Substring(1), out result)) result *= -1; } else { decimal.TryParse(match, out result); } return result; } }
Hi,
I'm not sure I am following you. What does a DataFilter have to do with Pasting?
Are you pasting text into the grid? Where is the text coming from? Are you handling the paste operation yourself or are you using the AllowMuliCellOperation functionality in the grid? Are you pasting a single cell or a group of cells or a whole row?
I have similar issue. I have column representing custom object. The column is bound to the type of the custom object. I am implementing IEditorDataFilter to display the custom object as text. On editing, I want allow user to enter / copy / paste text. And was hoping to convert the text to custom object in the DataFilter.
However when I paste the text, I get an error unable to cast string to custom object. The data filter does not get a chance to convert string to custom object.
Pasting into a cell should be the same as typing into the cell. So if the DataFilter is not getting called in this case, it sounds like it might be a bug.
Can you post a small sample project demonstrating this so we can check it out?