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

Dataformat when editing cells

4 Answers 207 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Kristjan Einarsson
Top achievements
Rank 1
Kristjan Einarsson asked on 19 Jan 2011, 12:57 PM
Hi,
I'm trying to display the value in a cell when editing double values without displaying decimals, see screenshot -> the edit cell format seems to be overridden.

So my question is can I easily format the editable cell ?

All my GridViewDataColumn's have this dataformat:
col.DataFormatString = "{0:N0}";

Thanks
Kristján

4 Answers, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 19 Jan 2011, 03:32 PM
Hello Kristjan Einarsson,

You may define the CellEditTemplate of the Column and set the StringFormat of the Binding:

<telerik:GridViewDataColumn DataMemberBinding="{Binding StadiumCapacity}"
         Header="Stadium"
         DataFormatString="{}{0:N4}">
  <telerik:GridViewDataColumn.CellEditTemplate>
     <DataTemplate>
          <TextBox Text="{Binding StadiumCapacity, StringFormat=N0}"  />
     </DataTemplate>
   </telerik:GridViewDataColumn.CellEditTemplate>
</telerik:GridViewDataColumn>
 

Kind regards,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
0
Kristjan Einarsson
Top achievements
Rank 1
answered on 20 Jan 2011, 09:50 AM
Thank you for your answer, it works like a charm for the columns that I know about, but I have some dynamic columns as well, I've been trying to do this in code behind without any success, is that possible to do that as well

Best regards
Kristján

0
Kristjan Einarsson
Top achievements
Rank 1
answered on 20 Jan 2011, 11:25 AM
Well I kinda found out
FrameworkElementFactory text = new FrameworkElementFactory(typeof(TextBox));
text.SetBinding(TextBox.TextProperty, new Binding("Values[" + i + "].Value") { Mode = BindingMode.TwoWay, StringFormat="N0" });
 
dt.VisualTree = text;
dt.Seal();
col.CellEditTemplate = dt;

This seems to work, only the fraction is forgotten, but I think I can take care of the in BeginEdit.

cheers
kristján
0
Maya
Telerik team
answered on 20 Jan 2011, 06:29 PM
Hello Kristjan Einarsson,

I am happy to see that you have found your solution out.
Let me know if you need any further assistance. 
 

Best wishes,
Maya
the Telerik team
Let us know about your Windows Phone 7 application built with RadControls and we will help you promote it. Learn more>>
Tags
GridView
Asked by
Kristjan Einarsson
Top achievements
Rank 1
Answers by
Maya
Telerik team
Kristjan Einarsson
Top achievements
Rank 1
Share this question
or