I have an UltraGrid bound to a list of elements.
One of the columns is of type double.
I want to conditionally calculate a text string based on user picking this else where:
But cell.Text is readonly
and
cell.Value throws an exception, because it wont let me set a string into a double columns value.
How can I do this?
private void fGrid1_InitializeRow(object sender, InitializeRowEventArgs e) { UltraGridCell cell = e.Row.Cells["ColName"];
cell.Text = DollarFormatting.FormatDollarValue((double)value, DollarsOrPercentage.Percentage, TotalForPercentage); }
I could be wrong - but I think.....
You want to set the value in the cell using .Value not with .Text.
e.Rows.Cells["ColName"].Value = whatever
The error you are getting makes sense; you should assign a double into a column that is expecting a double. The formating you want to do shouldn't be done using a string; instead you should be using an input mask.
The formatting I needto do requires a conditional mathematica operation.
I may have a solution based on using cell.Value and FormatString - but wheneverI set using cell.Value it puts the row into edit mode which then shows that icon in the row header.
How can I avoid that?
Hi,
It sounds like you don't really want to change the value, you just want to format it. The easiest way to do this is via the Format property of the column. Basically, when the grid displays the value of a cell, it calls the ToString method on the value and passes in the Format from the Format property.
So you should check the Microsoft documentation on the possible format's for a decimal and see if there is one which will suit your needs.
If there isn't then there are a couple of other options. You could use a DataFilter which allows you to intercept the value as it transitions between the editor and the display. The down side of this is that you have to go both directions - both formatting and unformatting the value.
If the cell is read-only (not editable by the user), then another option would be to use a DrawFilter. The DrawFilter allows you to override the drawing of the cell, so you can draw whatever you want.
Yet another option would be to hide the "real" bound column in the grid and add an unbound string column. You could use the InitializeRow event of the grid to format the value ihn the hidden column and set the Value of the unbound column.