Datagrid does not accept comma's

M

Maqsood Ahmed

Hello,
Here is the scenario:
I have a datagrid on a winform and a datatable is set as its
datasource. I have added DataGridTableStyle in datagrid's TableStyles
property. Some of Gridstyles are numeric (doubles) and I have set their
format to #,0.0000 since I want to display the values to comma seperated
(at thousands) and till four decimal places. User can also edit values
in the grid. So far so good.

The Problem:
Edited cell value reverts back to the previous value when the user
enters a comma formatted value. For example: original value was 52.0000
and user entered 1,000,000. IMO i should be displayed as 1,000,000.0000
but the value reverts back to 52.0000. I have tried to consume
CurrentCellChanged event of datagrid and also RowChanging/ColumnChanging
events.
- CurrentCellChanged event does not give me the new value from the
CurrencyManager.
- RowChanging/ColumnChanging events do not raise at all in the above
mentioned scenario.

Any thoughts/workarounds?

TIA.
Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 
M

Maqsood Ahmed

Hello,
Yes I am using the DataGridColumnStyles (DataGridTextBoxColumn). I have
associated double with the DataGridTextBoxColumn and set its format to
"#,0.0000". Actual problem is that it does not accept formatted input.
It works fine otherwise.

TIA
Maqsood Ahmed - MCAD.net
Kolachi Advanced Technologies
http://www.kolachi.net
 
C

Cor Ligthert [MVP]

Ahmed,

I can do the behaviour you describe when I use the "c" format and don't
delete the currency sign.

With this it goes in my opinion fine.

\\
DataTable dt = new DataTable();
dt.Columns.Add("decimal",Type.GetType("System.Double"));
dt.LoadDataRow(new Object[] { 111111.11 }, true);
dataGrid1.DataSource = dt;
DataGridTableStyle ts = new DataGridTableStyle();
ts.MappingName = dt.TableName;
DataGridTextBoxColumn tb = new DataGridTextBoxColumn();
tb.MappingName = "decimal";
tb.Format = "d";
ts.GridColumnStyles.Add(tb);
dataGrid1.TableStyles.Add(ts);
///

I hope this helps,

Cor
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top