Hello,
I have a request to display and accept negative numbers as numbers with parenthesis, for example, (450) represents -450
Does InputMask property support parenthesis in mask?
Please help ...
Hello Yogi,
My team and I have done an initial review of this issue, and I am a little unsure of what exactly you are looking to achieve. I have looked through our Windows Forms APIs and have not found any trace of an ITreeNodeColumn, and so I am not entirely sure what exactly that is. From your description, though, it sounds like you are looking to apply a Mask where if the value is within parenthesis, the editor that you are applying it to will evaluate it as a negative value?
If this is the case, this is not supported out of the box. There is no Mask that I know of that will allow you to have an input in parenthesis and evaluate that as a negative number.
I did notice that the UltraTextEditor is tagged in this forum thread. If you are using an UltraTextEditor, I don’t believe you will be able to apply a Mask anyway, as this editor cannot be masked. Assuming you are using this editor type, my best recommendation in this case would be to handle the ValueChanged event and parse the Value of the UltraTextEditor. If it is contained in parenthesis, set the Value of the editor to be the negative value of what is within those parenthesis.
Please let me know if you have any other questions or concerns on this matter.
Hi Andrew, sorry for the confusion, yes you are correct, ITreeNodeColumn is not part of Infragistics. But we do use Infragistics.Win.UltraWinTree.UltraTree class. And I think when we execute SetDataBinding, all the cells in the tree are built with types that match the datasource field types. Once the cell types are defined, it would not allow me to put a custom mask such as parenthesis on a decimal cell type. If only there was a way to override these cell types then I may be able to override and define some cell as string and then put my custom mask on numeric types. Or,is there a better approach to applying custom mask in numeric cells?
To clarify again:
Mask refers to an input mask. This only applies to the cell when it is in edit mode - that is, the cell is the ActiveCell and there's a blinking caret so the user can edit.
Format applies to the cell only when it is NOT in edit mode and just displaying normally.
You can format a cell using parens very easily. The DotNet framework has support for parens for negative values for most, if not all, numeric types. See the links I posted above to the standard and custom number formats in the DotNet framework.
If what you really want here is to mask the input then I'm not entirely sure what that would mean. You could create a mask with literal parens that always show up in the cell so that user is always entering a number between parens and therefore always entering a negative value. But if you want the parens to be optional and treated as negative only when the user enters them, the Infragistics masked editors don't support that. So if that's what you need - for the user to enter values optionally using parens, I would recommend not using a mask, but instead using a DataFilter to convert the string containing the parens into a negative value and the negative value back into a string.
If that is what you want, I could help you achieve it, but right now, I'm still very fuzzy on exactly what you want.
Hello Mike,
On Infragistics.Win.UltraWinTree.TreeNodesCollection , if I have an object of this type, let's say
Infragistics.Win.UltraWinTree.TreeNodesCollection x;
x.SetDataBinding(someDataSource, null)
then if I enumerate like this:
foreach (var n in m_treeNodes) { n.Cells[8].Column.DataType = typeof(string); n.Cells[8].Value = "(100)"; }
let's say Cells[8] exists, even though I was able to assign a string type to the column, I still could not assign "(100)" to the cell because somehow the cell keeps its type as decimal from the datasource.
So in this case I would get a run time error: Object of type 'System.String' cannot be converted to type 'System.Decimal'
So what would it take for me to override this decimal type from datasource?
You can't change the DataType of a column that is bound. The DataType is determined by the data source. The tree has to be able to write the cell values to the data source, so changing the data type doesn't make sense.
It's still not clear to me if you are trying to format the cell data or mask the input. Which one do you need to do?
Hi Mike, I actually need to do both, format the cell, and mask the input to accept parenthesis because they want to be able to paste the amounts from Excel, and see the negative values as numbers in parenthesis. Yes I agree, changing overriding the cell types doesn't make sense. I'm just not clear how and where I can convert that string to decimal. Thank you Mike.
Oh thank you so much Mike, we did not expect you went thru the trouble creating the sample application. But me and our team appreciate your help very much. I will give it a try and get back with you to share our experience.
Thanks again!
Now that I feel like I have a pretty good idea of what you want, I went ahead and created a sample project to test some of it out. And even without a mask, everything seems to work for me.
If you run my sample, you can see I have an UltraTree with some data. In both the parent and child nodes, I have a column called "decimal 1" which displays a decimal value and I am applying a Format to the column (in the UltraTree1_ColumnSetGenerated event) that makes it display negative values in parens. So far, so good.
There's no way to select a range of cells in the tree, so presumably your users are copying a single value from an Excel sheet into a single cell in the tree. So I have an UltraSpreadsheet on there and you can select a cell in the spreadsheet that contains a negative value and copy it (Ctrl+C), then click on a cell in the tree in the decimal 1 column to enter edit mode. Select all of the text in the cell and press Ctrl+V. Now... at this point, the cell with display the value with a negative sign instead of parens. I don't think that's a big problem, and Excel behaves the same say. If you click into an cell in the spreadsheet and press F2 to enter edit mode, it also shows with a negative sign instead of the parens. The parens are only for display, not for editing. And when you leave the tree cell, it once again shows the negative value with parens.
So... the only potential problem I can see here is that the cell shows the negative sign when in edit mode. But there's really nothing you can do about that and it's standard behavior even in Excel. WindowsFormsApplication8.zip
UltraWinGrid can display hierarchical data. But UltraSpreadsheet cannot.
So if you have the option, switching to the grid might be a good idea. But if you don't want to do that because it would be too big a change to re-write all of the application code that's currently working with the tree, I understand.
Like I said... I don't believe it's possible to mask the input of a tree cell using parens like you want. There are a number of approaches you could try, such as not using a mask, but simply letting the user type into the cell freeform and then trying to parse the parens if they are there and convert them. But there is no mask functionality to allow for optional parens.
But again... masking is for typing into a cell. If all you are concerned about here is copying and pasting, then you don't need to worry about the mask. You will have to get the data from the clipboard and parse it in code, anyway. So a mask is irrelevant.
I agree, doing copy and paste onto a Tree is really not my thing. The reason I have to work with this UltraTree is because the software has been written, and it is handling a Cost Worksheet that involves drill-down of accounts and subaccounts. And not only that, the previous team of developers developed a wrapper class around Infragistics UltraTree that even added complexity with its extra properties, methods, and what nots. The top layer of the Tree node is created by instantiating this wrapper class. Maybe this was done to facilitate the copy and paste.
I think the UltraGrid and UltraSpreadhseet may not have drilldown functionality, is that a correct statement?
Sadly, many people still work with Excel, custom software at the same time. They would copy and paste from one to the other, and having two monitors is a real treat for them to keep this bad habit alive.
Well if you have any sample code to mask user input with parenthesis on a single cell, at least maybe I can see how that is done, if that can be done?
Okay. It's definitely possible to format the values using parens. But as I said, I'm not sure if masking is possible.
Also... the tree doesn't natively support copy and paste, so you would have to implement that yourself. In which case, there's really no reason I can see why the mask would matter. If you are copying data from Excel, then you could handle simply extracting the value from the clipboard and setting the value of the cell. You don't need to deal with masking. Masking is for USER input - like when a user it typing into a cell. It shouldn't affect pasting. Unless maybe the user is pasting a string into a single cell. And even then, you could handle getting the data from the clipboard and converting it if you need to.
It might be easier for you to use an UltraGrid instead of UltraTree. The grid has built-in copy and paste functionality and can accept copying data from Excel.
In fact, an even better choice might be to just use the UltraSpreadsheet, which is essentially exactly like Excel.
Is there some reason you are using an tree here to show spreadsheet data?