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. (Last updated on : November 16, 2018).
Unfortunately, activation email could not send to your email. Please try again.
Syncfusion Feedback

MaskEdit cells in a GridGroupingControl mapped to a double

Thread ID:

Created:

Updated:

Platform:

Replies:

51315 Nov 2,2006 06:05 PM UTC Nov 7,2006 11:55 AM UTC WinForms 5
loading
Tags: GridControl
Eric Castillo
Asked On November 2, 2006 06:05 PM UTC

I have a couple of questions regarding MaskEdit cells in a GridGroupingControl that are mapped to a property of an object that is a double.

I kind of pieced this code together based on snippets from this board and from examples:

GridColumnDescriptor descriptor = new GridColumnDescriptor("Number", "Number", "Number", false);
GridTableCellStyleInfo info = new GridTableCellStyleInfo();
info.CellType = GridCellTypeName.MaskEdit;
info.CellValueType = typeof (double);
info.ReadOnly = false;
info.MaskEdit.PaddingCharacter = '\0';
info.MaskEdit.PassivePromptCharacter = '\0';
info.MaskEdit.PromptCharacter = '\0';
info.MaskEdit.Mask = "###.00%";

GridTableCellAppearance appearance = new GridTableCellAppearance();
appearance.AnyRecordFieldCell = info;
appearance.RecordFieldCell = info;
appearance.AlternateRecordFieldCell = info;
descriptor.Appearance = appearance;
GridColumnDescriptorCollection collection = new GridColumnDescriptorCollection();
collection.Add(descriptor);

The idea is I want an editable grid bound to a list of business objects. One of the columns I want editable is bound to a double representing a percentage value. (The example I sent you uses a MaskEdit for cells in this column, but it may not stay that way.)

Questions:
1) When I try to modify a cell in that column to 25%, I get a popup reading the following: "25.00% is not a valid value for a double." It appears that the value returned by the cell is the string "25.00%" and cannot be converted to the underlying double I want to store into. How can I get this value back into my underlying object represented by the given row? (Or is my approach all wrong?)

2) What I do like is the exclamation point next to my value indicating an invalid value. I do eventually want to validate the value of the modified cell, confirming it's between 0 and 100 percent. How can I do this, and do so without the popup, only the red exclamation point indicator?

Any insight would be greatly appreciated.

Thanks!

Eric



Test49.zip

Administrator [Syncfusion]
Replied On November 3, 2006 05:51 AM UTC

Hi Eric,

Please refer to the below forum thread for customize the ErrorIcon and its ErrorMessageBox.
http://www.syncfusion.com/support/Forums/message.aspx?&MessageID=46953

Best Regars,
Haneef

Eric Castillo
Replied On November 6, 2006 09:28 PM UTC

Haneef,

I read the referenced thread, and fiddled with overriding the validating behavior of the grid, but this still can't figure out how to get around issue 1, which is binding the column to an underlying double. If you could, please be a bit more explicit about how to go about doing this.

Many thanks in advance,

Eric

Eric Castillo
Replied On November 6, 2006 10:05 PM UTC

Let me be more specific about my requirements, since I realize I wasn't that clear initially:

1) I have a binding list of TestClass objects, each of which has one accessor of type double:

class TestClass {
private double percentage;

public double Percentage {
get { return percentage; }
set { val = percentage; }
}
}

2) I set my gridGroupControl.DataSource equal to this binding list of TestClass objects.

3) I would like to be able to modify the TestClass objects via the grid; specifically, I'd like to change the values mapped to the Percentage properties

4) I would like to display the percentages in the grid with a "%" suffix.

5) I would like to validate that the specified percentage >= 0 and <= 100.

6) If the user attempts to leave the cell after having typed in garbage letters in the Percentage column, I would like to allow the user to do so, and not to still display whatever it was the user typed, not clear out the contents of cell to zero.

So the biggest obstacle I confront is that, while this works when the mapped property for the column is a string, when it is a double, I get validation errors that I cannot get around. For example, if I attempt to leave a cell with the text "ab.00%", the value will clear out to 0.00%. If I leave the cell in the state "24.00%" then I get a popup saying that that string cannot be converted to a double.

So is there a way around this?

Thanks, and apologies if the referenced thread to which you pointed me has this answer, I just can't figure it out.

Eric

conecc@capgroup.com
Replied On November 6, 2006 10:07 PM UTC

6) If the user attempts to leave the cell after having typed in garbage letters in the Percentage column, I would like to allow the user to do so, AND TO still display whatever it was the user typed, not clear out the contents of cell to zero.

Administrator [Syncfusion]
Replied On November 7, 2006 11:55 AM UTC


Hi Eric,

This can be acheived by handling the TableControlCurrentCellValidating event and set the Renderer.ControlText to valid value. And also you can handle the TableCotrolDrawCell event to dynamically draw the incorrect format in a cell. Please try the attached sample and let me know if you looking something different. Some code snippet below.

void gridGroupingControl1_TableControlCurrentCellValidating(object sender, GridTableControlCancelEventArgs e)
{
GridCurrentCell cc = e.TableControl.CurrentCell;
Double d ;
string s = cc.Renderer.ControlText;
s= s.Replace("%", "");
if (Double.TryParse(s, out d) && d >= 0 && d <= 100 )
{
RemoveDisplayValue(cc.RowIndex);
cc.Renderer.ControlText = s;
}
else
{
setDisplayValue(cc.RowIndex, cc.Renderer.ControlText);
cc.Renderer.ControlText = "0.00";
}
}

Here is a sample.
http://www.syncfusion.com/Support/user/uploads/CellRendererTest_a96f373d.zip

Best Regards,
Haneef

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.

Warning Icon 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.Close Icon

;