This is a migrated thread and some comments may be shown as answers.

How to change formatting on specific cells

0 Answers 80 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Ingólfur
Top achievements
Rank 1
Ingólfur asked on 31 Aug 2012, 10:28 AM

So I have a dynamic RadGridView using MVVM and Caliburn Micro. This means that I add Columns programmatically to the control. basically like this:

for (int i = 0; i < length; i++)
{
    Binding b = new Binding(string.Format("Collection[{0}].ValueIWant", i));
    binding.StringFormat = "{0:0.##}";
    GridViewDataColumn column = new GridViewDataColumn()
    {
        Header = HeaderFor(i),
        DataMemberBinding = b,
        DataType = typeof(double?)
    };

    Control.columns.Add(column);
}

Now I need to add new lines that show the percentage between line 1 and 22 and 3 and so on.

I've managed to do that but I'm not sure how I would manage to change the String.format specifically for those cells instead of the whole column.

CellTemplateSelector came to mind but I'm not sure that is a good idea as this might mean I have to set the binding again, not knowing the value of i and such. Also I only want to change the string.format on the binding.

As I'm manipulating the number as a double (0,5 is 50%, 50 is 5000%) I guess I have to mask the input as well. not sure if String.Format does that for me as well or if I should use RadMaskedInput

No answers yet. Maybe you can help?

Tags
GridView
Asked by
Ingólfur
Top achievements
Rank 1
Share this question
or