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. Image for the cookie policy date

System.single display question??

Whats the best CellType and CellValueType to use when displaying a value that is a single and has a floating decimal place? For instance, sometimes my single value might be 834 or another it might be 834.34 or another it might be 834.345678. We normally use a currency celltype but in this case I don't know how to always make it show the whole value when I dont know exactly how many digits might be after the decimal. So since I never know the number of decimal places after the decimal for sure, is it best to use the TextBox CellType with a CellValueType of System.Single or is there some way to make the currency cell work with a floating decimal?

20 Replies

PB Philip Bishop August 28, 2007 12:36 PM UTC

Also the reason we've always used the currency cell in the past is because then we dont have to put in any extra code to check for non numeric key strokes and not allow them. That's why I was trying to stick with the currency cell with some sort of a floating decimal place.


AJ Ajish Syncfusion Team August 29, 2007 01:01 AM UTC

Hi Philip,

You can go for the TextBox celltype and the cellvaluetype as double/single for your needs. You can restrict the non-numeric entries to the cell handling the CurrentCellKeyPress event. To get the desired format for the cells, set the format in the grid.Model.QueryCellInfo event handler. Please try the below code snippets.


void gridControl1_CurrentCellKeyPress(object sender, KeyPressEventArgs e)
{
if (!char.IsNumber(e.KeyChar))
e.Handled = true;

else if(e.KeyChar == '.')
{
GridControl grid = sender as GridControl;
GridCurrentCell cc = grid.CurrentCell;
if( cc != null )
{
string sCellText = cc.Renderer.ControlText;
if( sCellText.Indexof(".") != -1 )
{
e.Handled = true;
}
}
}

void gridControl1_QueryCellInfo(object sender, GridQueryCellInfoEventArgs e)
{
if(e.Style.CellValueType == typeof(double))
e.Style.Format = "#.############";
}

Kindly take a look and let me know if you need any further details,

Regards,
Ajish.


PB Philip Bishop August 29, 2007 05:41 PM UTC

I knew would use the text box cell but I didn't want to have to check the key press and only allow certain keys. Can you do this with a currency cell and have the floating pattern like you showed me?


PB Philip Bishop August 31, 2007 07:50 PM UTC

Ok I have a problem with this that I cant seem to figure out. In my sample I have a grid that has row1 as textbox celltype and row2 is currency cell type. If you paste text in to a cell in row one it will allow it and then give me your generic message when I move off the cell. If you paste the same text in to row2, it will then go to my paste cell text event and give you my message which is what I want. Why does the row that has text cells not go to the pastecelltext event but the one with a currency cell type does? I have a keypress event to stop the user from entering text and I dont want them to be able to paste text. Thanks in advance.


AJ Ajish Syncfusion Team September 4, 2007 12:03 AM UTC

Hi Phil,

Sorry for the delay in getting back to you. We will investigate on this issue and provide you with an update within 1 business day.

Regards,
Ajish.


PB Philip Bishop September 4, 2007 02:13 PM UTC

OK. I will wait and see what you come up with. Also I had asked if there is a way to use your currency cell and have the decimal point float? The problem I am having with all of this is that I never know how many decimal places there will be in each cell. This data is coming from a factoring program and the user then can edit it in your grid. So that is why we went to a textbox cell instead of currency. Is this possible in a currency cell and then I wouldn't have this pastecelltext problem I am having in the currency cell


PB Philip Bishop September 4, 2007 03:07 PM UTC

I forgot to attach the sample for the question about the pastecelltext event problem. Here it is. I also am still curious about a currencycell with a floating decimal as I posted before this.

MultipleGridsShowingProb.zip


AJ Ajish Syncfusion Team September 4, 2007 11:59 PM UTC

Hi Philip,

You can set the CurrencyEdit.CurrencyDecimalDigits property of the styleinfo object to specify the number of digits that can appear after decimal in a currency cell. The desired functionlaity can be easily achieved by having a TextBox celltype with the formatting applied to it. Please take a look at the below sample

http://websamples.syncfusion.com/samples/Grid.Windows/F67660/main.htm

The PasteCellText works fine for both TextBox and Currency cells in the above sample. This event gets fired on cell basis whenever paste is done. I will look into your problem in the sample and get back to you with more details.

Regards,
Ajish.


PB Philip Bishop September 5, 2007 01:58 AM UTC

Ok I will look at that tomorrow. Please look at my sample because what you say you have working with a text cell and paste text event doesn't work in my sample.


PB Philip Bishop September 5, 2007 12:54 PM UTC

Ok I think you are missing the point. First, your sample doesn't work. It's shows this reference of 'Syncfusion.XlsIO.Base' as having issues or not found. I searched for that and I dont have that.

Secondly it doesn't even have a paste cell text event. You need to just look at my sample please.

Third, I think you are missing what I am saying about the decimal places. I never know for sure how many places there are because of a factoring program that happens before I display the data in the grid. There might be 3 after the decimal or 7 or 8 or none. It's always different. That's why I went to the text box instead of the currency cell. That is where I ran in to the problem with my pastecell event.



AJ Ajish Syncfusion Team September 6, 2007 01:00 AM UTC

Hi Philip,

Here is the details regarding your query,

1) DecimalPlaces problem in currency cell.

- Inorder to make the currency cell to display for any number of digits you need to set the the decimal digits property to the maximum value that is expected and the zeros can be removed using the following code.

private void gridControl1_CurrentCellControlGotFocus(object sender, ControlEventArgs e)
{
GridCurrencyTextBox gtx = e.Control as GridCurrencyTextBox;
if (gtx != null)
{
gtx.RemoveDecimalZeros = true;
}
}

//For changing the ending zeros

void gridControl1_DrawCellDisplayText(object sender, GridDrawCellDisplayTextEventArgs e)
{


if (e.Style.CellType == "Currency")
{
e.DisplayText = e.DisplayText.Replace("0", "");

}
}

2) paste text event doesn't work in my sample.

- I am able to reproduce the issue with the sample provided to us. If you copy from a GridControl and paste in a GridControl, then by default style objects are copied and pasted, and PasteCellText is not raised. To see the PasteCellText event raised, you can turn off support for copying styles (allowing only text to be pasted and PasteCellText to be hit). To turn off style copy/paste support in a gridcontrol, turn off this flag.


this.gridControl1.Model.CutPaste.ClipboardFlags &= ~GridDragDropFlags.Styles;


Kindly try the above and let me know if this helps.

Regards,
Ajish.

>>>

Regards,
Ajish.


PB Philip Bishop September 6, 2007 02:26 PM UTC

Ok the styles does not fix the pastecell text event. I had that in my live version but in my test I sent you it was commented out. Regardless that does not solve the problem

Your GTX.removedecimalzeros doesn't work for me either. When I do gtx. I dont even see removedecimalzeros. Is there something I am missing?


PB Philip Bishop September 7, 2007 03:33 PM UTC

Oh and we do VB.net


HA haneefm Syncfusion Team September 7, 2007 09:01 PM UTC

Hi Philip,

I could see the PaseCellText does not fired issue when copy the single cell and paste it in grid textbox cell. You can solve this issue by handling the CurrentCellKeyDown event of the grid. Here are the modified code that shows this task.

//Form's Load event.
this.gridControl1.Model.CutPaste.ClipboardFlags = GridDragDropFlags.Text;

private void gridControl1_CurrentCellKeyDown(object sender, KeyEventArgs e)
{
if (e.KeyCode == Keys.V && e.Modifiers == Keys.Control)
{
String _strText = Clipboard.GetData(DataFormats.Text) as String;
if (_strText.Split(new string[] { "\t", Environment.NewLine }, StringSplitOptions.None).Length == 1)
{
e.Handled = true;
GridControl _grid = sender as GridControl;
GridCurrentCell _cc = _grid.CurrentCell;
_grid.Model.TextDataExchange.PasteTextRowCol(_cc.RowIndex, _cc.ColIndex, _strText);
}
}
}

Please refer to the attached sample for implementation and let me know if this helps.
WindowsApplication45.zip

Also attached sample also implements the custom celltype that shows you "How to prevent the non-numeric keystroke and fires the PasteCellTextEvent in a grid textbox cell?".

Best regards,
Haneef


PB Philip Bishop September 10, 2007 12:41 PM UTC

Ok I have one last thing that didn't get answered in all of this. You had given me some code to remove the zeros in a currency cell that had decimals. For instance I might have 43.890000000. You had give me gtx.removedecimalzeros and that never was an option for me when I tried it. Do I have to do something special to get it? I tried your could and it never shows up. Also if you give me some code back can you give VB code?

Thanks


HA haneefm Syncfusion Team September 10, 2007 03:25 PM UTC

Hi Philip,

Here is a VBsample that implement the RemoveDecimalZeros property in a grid currency cell. Please try the sample and let me know if this helps.
GridCurrencyCellsVB.zip

Best regards,
Haneef


PB Philip Bishop September 10, 2007 03:35 PM UTC

I am getting the same error I was before. When I run it I get the build error as follows....

Error 1 'RemoveDecimalZeros' is not a member of 'Syncfusion.Windows.Forms.Grid.GridCurrencyTextBox'. C:\syncfusion\RemoveDecimalDigits\GridCurrencyCellsVB\Form1.vb 83 13 GridCurrencyCellsVB

I am using versino 4.2 of the grid if that makes a difference


HA haneefm Syncfusion Team September 11, 2007 12:02 AM UTC

Hi Philip,

Sorry for the inconvenience caused.

In Essential Studio 4.2, There is no member named RemoveDecimalZeros property in GridCurrencyTextBox control. It has newly added in Essential Studio V4.4. But one way you can solve this issue by using the TextBox celltype and the cellvaluetype as double/single for your needs. You can restrict the non-numeric entries to the cell handling the CurrentCellKeyPress event. To get the desired format for the cells, set the format in the grid.Model.QueryCellInfo event handler. You can handle the CurrentCellKeyDown event for Pasting issue in a GridTextBoxCell.

Thanks for your patience.

Best Regards,
Haneef


PB Philip Bishop September 11, 2007 01:07 PM UTC

Are there any issues if I was to install version 5 and keep versin 4.2 for apps that we don't need this for?


HA haneefm Syncfusion Team September 11, 2007 11:30 PM UTC

Hi Philip,

Are there any issues if I was to install version 5 and keep versin 4.2 for apps that we don't need this for?
>>>>>>>
No, Our latest version 5.2 has been released with lot of bug fixes and features enhancements. Please try installing the latest version and let me know if let me know if you see any problem.

Best regards,
Haneef

Loader.
Live Chat Icon For mobile
Up arrow icon