We use cookies to give you the best experience on our website. If you continue to browse, then you agree to our privacy policy and cookie policy.
Unfortunately, activation email could not send to your email. Please try again.

DoubleEdit

Thread ID:

Created:

Updated:

Platform:

Replies:

82280 Jun 8,2009 11:15 AM Jun 10,2009 11:39 AM WPF 5
loading
Tags: GridControl
Andrew Snyder
Asked On June 8, 2009 11:15 AM


I am try to set a cell to be a double edit box showing only 2 decimal places, but when i begin to edit i would like the end user to enter more than 2 decimal places. Trying to change the cell back to a TextBox seem to cause a crash. Is there a way to achieve this behavior with the DoubleEdit?

//causes crash expecting DoubleEdit
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.Cell == CurrentCell.CellRowColumnIndex)
{
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "TextBox";
}
else
{
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "DoubleEdit";
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].NumberFormat = new NumberFormatInfo { NumberGroupSeparator = ",", NumberDecimalSeparator = ".", NumberDecimalDigits = 2 };
}
e.Style.CellValue = _dataSource[e.Cell.RowIndex, e.Cell.ColumnIndex];
}


//remains a DoubleEdit
void Model_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if (e.Cell == CurrentCell.CellRowColumnIndex && CurrentCell.IsInBeginEdit)
{
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "TextBox";
}
else
{
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "DoubleEdit";
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].NumberFormat = new NumberFormatInfo { NumberGroupSeparator = ",", NumberDecimalSeparator = ".", NumberDecimalDigits = 2 };
}
e.Style.CellValue = _dataSource[e.Cell.RowIndex, e.Cell.ColumnIndex];
}

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On June 9, 2009 05:45 AM

Hi Andrew,

The DoubleEdit works with the NumberFormat that you set, so if your NumberFormat says it has "3" decimal digits, you simply set the NumberFormat.NumberDecimalDigits property, and it should automatically get applied to the DoubleEdit cell type.

Regarding the crash, Can you please post the Stack trace that you get, this should help discover the cause of the issue.

Please let me know if you want any more details.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

Andrew Snyder
Replied On June 9, 2009 08:53 AM

The crash happens when i try to get into edit mode.

An unhandled exception of type 'System.InvalidCastException' occurred in Syncfusion.Grid.Wpf.dll

Additional information: CurrentCellUIElement should be of type DoubleTextBox

> Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCellRendererBase.CurrentCellUIElement.set(System.Windows.UIElement value = {System.Windows.Controls.TextBox: 1.2222}) Line 204 C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCellRendererBase.SetCurrentCellState(Syncfusion.Windows.Controls.Grid.GridControlBase gridControl = {DataWindow.SampleGridControl}, Syncfusion.Windows.Controls.Cells.RowColumnIndex cellRowColumnIndex = {RowColumnPosition { RowIndex = 2, ColumnIndex = 2}}, Syncfusion.Windows.Controls.Grid.GridActivateCurrentCellOptions options = {Syncfusion.Windows.Controls.Grid.GridActivateCurrentCellOptions}) Line 220 + 0x1e bytes C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridVirtualizingCellRenderer.RefreshContent() Line 184 + 0x44 bytes C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCellNumericEditBaseCellRenderer.RefreshContent() Line 174 + 0x8 bytes C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCurrentCell.CreateCurrentCellUIElements() Line 669 + 0xc bytes C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCurrentCell.BeginEdit(bool focusCellUIElement = true) Line 733 + 0xe bytes C#
Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridSelectCellsMouseController.MouseDown(Syncfusion.Windows.Controls.Scroll.MouseControllerEventArgs e = {Syncfusion.Windows.Controls.Scroll.MouseControllerEventArgs}) Line 852 + 0x20 bytes C#
Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseControllerDispatcher.MouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}, bool isPreview = false) Line 715 + 0x1d bytes C#
Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseControllerDispatcher.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 573 + 0xd bytes C#
Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseEventTargetCollection.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 53 + 0xc bytes C#
Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.ScrollControl.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 1228 + 0x13 bytes C#




As for the second example why can i not change the box back to a text box when i am going into edit mode?

if (e.Cell == CurrentCell.CellRowColumnIndex && CurrentCell.IsInBeginEdit)
{
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "TextBox";
}

Mohamed Suhaib Fahad A. [Syncfusion]
Replied On June 9, 2009 09:29 AM

Hi Andrew,

Thanks for the details provided. The Grid maintains a CurrentCell state internally so that everything is in sync. When you try to change the active cell's CellType, that exception gets thrown. Best way would be to set change the active cell's CellType after you call this method,

this.grid.CurrentCell.Deactivate();

This method will reset the CurrentCell's state and the exception will not be thrown. Le t me know if this helps you out.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

Andrew Snyder
Replied On June 9, 2009 11:27 AM

I have tried:
CurrentCell.Deactivate();
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "TextBox";

but then an exception is thrown when i try to begin editing:
Object reference not set to an instance of an object.
> Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridCurrentCell.BeginEdit(bool focusCellUIElement = true) Line 734 + 0x7 bytes C# Syncfusion.Grid.Wpf.dll!Syncfusion.Windows.Controls.Grid.GridSelectCellsMouseController.MouseDown(Syncfusion.Windows.Controls.Scroll.MouseControllerEventArgs e = {Syncfusion.Windows.Controls.Scroll.MouseControllerEventArgs}) Line 852 + 0x20 bytes C# Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseControllerDispatcher.MouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}, bool isPreview = false) Line 715 + 0x1d bytes C# Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseControllerDispatcher.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 573 + 0xd bytes C# Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.MouseEventTargetCollection.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 53 + 0xc bytes C# Syncfusion.GridCommon.WPF.dll!Syncfusion.Windows.Controls.Scroll.ScrollControl.OnMouseDown(System.Windows.Input.MouseButtonEventArgs e = {System.Windows.Input.MouseButtonEventArgs}) Line 1228 + 0x13 bytes C#


so i then tried

CurrentCell.Deactivate();
Model[e.Cell.RowIndex, e.Cell.ColumnIndex].CellType = "TextBox";
CurrentCell.Activate(e.Cell, new GridActivateCurrentCellOptions(GridSetCurrentCellOptions.ForceRefresh));

but the value does not appear in the text box and it will not let me edit




Mohamed Suhaib Fahad A. [Syncfusion]
Replied On June 10, 2009 11:39 AM

Hi Andrew,

The exceptions are getting thrown because of improper typing at runtime. Changing the CellType at runtime will actually cause some abnormal behavior in the work flow of the grid, and so it is not advisable to do that.

As per your initial requirements, I have a sample prepared that will have NumberDecimalDigits set to 2 before showing the original values, and uses a TextBox control. Since the DoubleEdit control doesn't have a feature to allow any number of decimal spaces, because it uses the NumberFormatInfo, I guess using a text box would be easy. But, doing this will actually remove all the functionalities that the DoubleEdit provides.

www.syncfusion.com/development/uploads/82280_6_10.zip

More appropriate would be that you set some max decimal digits for the DoubleEdit and override the OnRender method (as in the sample) and simply render out the result value with '2' decimal digits.

Please check it out and let me know if that helps you out.

Thanks,
Fahad
Grid.WPF Team
Syncfusion Inc.,

CONFIRMATION

This post will be permanently deleted. Are you sure you want to continue?

Sorry, An error occured while processing your request. Please try again later.

You are using an outdated version of Internet Explorer that may not display all features of this and other websites. Upgrade to Internet Explorer 8 or newer for a better experience.

;