Hello,
I read a couple of posts about this, but wasn't able to find a satisfactory solution. I've read these docs referenced in the posts:
http://devcenter.infragistics.com/Support/KnowledgeBaseArticle.aspx?ArticleID=4877http://help.infragistics.com/Help/NetAdvantage/NET/2007.3/CLR2.0/html/WinGrid_Formatting_Cells_Containing_Specific_Number_of_Characters.html
but,
Andrea said:how can I use a UltraNumericEditor in a data binded grid cell?
You would use the EditorControl property of the column.
Andrea said:it's difficult to me to believe that I have to implement a percentage logic in a datafilter. Do I really have to?
It depends what you want to do.
Andrea said:instead of using a number of classes, interfaces and coding the trivial percentage concept, how can I follow the event way and manually manage the value-format of the number in the cell?
You could hide the "real" databound column in the grid and add an unbound column. Then you would use the InitializeRow event to populate the unbound column with a string based on the real column's value and use AfterCellUpdate to go the other way, copying the unbound column value to the "real" cell.
Thanks Mike. At last it worked well.
The only thing is that I wasn't able to add a '%' simbol at the end of the edit pattern to be shown in the control. I tried with
this.ultraNumericEditor1.MaskInput = "nnn\\%";
but the simbol dosn't appear.
However I had to tell to the DataFilter in my control to behave like a percentual, hence I tell it to multiply by 100 and divide by 100... This point sounded me strange. Why not provide some BasicDataFilters (e.g for percent, sexagesimal to decimal, and so on)?
Hi Duhg,
i too had the same problem with percentage edit in the ultragridcell
i have followed your code and it worked fine for me.
am also displaying the summary values but the summary values are not displayed correctly .can you also send the SUMMARY DISPLAY code to display correct summary values
please can you do me this favour as soon as possible.its very urgent
Regards
Priyanka
Here is the code from the control that houses the grid. I have ripped out the stuff that is not related to the summaries.
private void ultraGridOptimizationBudgets_InitializeLayout(object sender, InitializeLayoutEventArgs e) { foreach (UltraGridBand band in e.Layout.Bands) { configureBandColumns(band); } } private void configureBandColumns(UltraGridBand band) { foreach (UltraGridColumn col in band.Columns) { createSummaryCell(band, col); } } private static void createSummaryCell(UltraGridBand band, UltraGridColumn col) { SummarySettings summary = band.Summaries.Add( col.Key, SummaryType.Custom, new CustomSummary(), col, SummaryPosition.UseSummaryPositionColumn, col); summary.Appearance.TextHAlign = HAlign.Right; }
private
void ultraGridOptimizationBudgets_InitializeLayout(object sender, InitializeLayoutEventArgs e) {
{
foreach (UltraGridBand band in e.Layout.Bands) { configureBandColumns(band); } }
configureBandColumns(band);
}
void configureBandColumns(UltraGridBand band) {
foreach (UltraGridColumn col in band.Columns) { createSummaryCell(band, col); } }
createSummaryCell(band, col);
static void createSummaryCell(UltraGridBand band, UltraGridColumn col) { SummarySettings summary = band.Summaries.Add( col.Key, SummaryType.Custom,
SummarySettings summary = band.Summaries.Add(
col.Key, SummaryType.Custom,
new CustomSummary(), col, SummaryPosition.UseSummaryPositionColumn, col); summary.Appearance.TextHAlign = HAlign.Right; }
col, SummaryPosition.UseSummaryPositionColumn, col);
summary.Appearance.TextHAlign = HAlign.Right;
I apologize for the layout of the code. The editor in this forum does not seem to be condusive to pasting code.
Hey Thanks For your reply
i need to put the code u sent and check whether it works fine.Thanks a ton
I too have been dealing with the same issue. I was able to successfully use the BeforeEnterEditMode and BeforeExitEditMode as you are doing (multiply by 100 when entering and divide by 100 upon exit).
The problem I am seeing though is with the formatting. In InitializeLayout, I am setting the column's Format property to be "#0.00%" so that I get a percentage value with 2 decimal places.
The UltraNumericEditor that I have associated with the column's EditorControl has it's MaskInput property set to "nnn.nn". This allows me to enter in values like 12.25 into the editor during edit mode. When I set a breakpoint in the BeforeExitEditModes, the value that I am placing in the active cell's value is 0.1225D (12.25 / 100 ) which seems correct. I would have expected the Format on the cell to then multiply by 100 since the format is "#0.00%, yielding 12.25%. Instead, it rounds the decimal places and I am left with 12.00% in the cell. Likewise, it I enter in 12.51, the result in the cell upon exit will be 13.00. When I enter back into edit mode, the values are 12 and 13 respectively.
What am I missing here?
I don't know.I have avoided associating an UltraNumericEditor.
OK. I figured out what was going on, in case it helps someone else.
It did NOT have to do with using an UltraNumericEditor. I removed that and just used the column's .Style = ColumnStyle.DoubleNonNegative and set the column's .MaskInput = nnn.nn.
I was still seeing the issue when I entered in 12.25, the result was still 12.00% after edit. The problem was with the .MaskInput. In my BeforeExitEditMode, I was taking the 12.25 and divding by 100 and setting the ActiveCell's .Value to .1225. The problem here was that because we are STILL in edit mode, the .MaskInput only accepts 2 decimal places. In Visual Studio, if you look at the ActiveCell after you assign the value but before you leave the BeforeExitMode, the ActiveCell's .Value it was .1225, but the .Text was ___.13.
To fix this issue, I altered the BeforeEnterEditMode and BeforeExitEditMode methods. Using the example from 04/07/2009 above, the event methods would look like
private void ultraGridOptimizationBudgets_BeforeEnterEditMode(object sender, System.ComponentModel.CancelEventArgs e){ UltraGridCell activeCell = ((UltraGrid)sender).ActiveCell; if (cellIsInPercentMode(activeCell)) { decimal value = cellValue(activeCell.Value.ToString()); if (value != 0) { activeCell.Value = value * 100m;
activeCell.MaskInput = "nnn.nn" } }} private void ultraGridOptimizationBudgets_BeforeExitEditMode(object sender, Infragistics.Win.UltraWinGrid.BeforeExitEditModeEventArgs e){ UltraGridCell activeCell = ((UltraGrid)sender).ActiveCell; if (cellIsInPercentMode(activeCell)) { decimal value = cellValue(activeCell.Text); if (value != 0) { activeCell.MaskInput = "nnn.nnnn" //Temporarily allow 4 decimal digits before assigning the value
activeCell.Value = value / 100m; } }}
I'm getting an error when running at full speed -- not when stepping through in debug mode:Operation can not be performed when not in edit mode which is happening after _BeforeEnterEditMode completes.
If I click the Continue button everything works fine. This only happens the first time I try and edit a column with a format="p". If I click off that cell and back it works fine. If I comment out the underlined code (in the example shown below) I do not get the error.
I am using UltraWinGrid v7.3.20073.38
Here's the applicable exception text:
System.InvalidOperationException: Operation can not be performed when not in edit mode.
at Infragistics.Win.EditorWithMask.EnsureInEditMode() at Infragistics.Win.EditorWithMask.SelectAll() at Infragistics.Win.UltraWinGrid.UltraGridCell.SelectAll()
Here's my VB version of this code:
Private Sub grdPayPlanning_BeforeEnterEditMode(… Dim cell As UltraGridCell = sender.activecell If cell.Column.Format = "p" Then Dim d As Double = cell.Value cell.Value = d * 100 cell.Column.MaskInput = "nnn.nn%" ' <--- Comment this line out End If End Sub
Private Sub grdPayPlanning_BeforeExitEditMode(… Dim cell As UltraGridCell = sender.activecell If cell.Column.Format = "p" Then Dim d As Double = cell.EditorResolved.Value cell.Column.MaskInput = "nnn.nnnn%" cell.Value = d / 100 End If End Sub
This will take some investigating. I suggest that you open a support case with Developer Support.
They should be able to delve into this and find a resolution to the issue. It will be especially helpful if you can provide a sample which demonstrates the error you are getting.