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

number format only for first row

3 Answers 137 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Viktor
Top achievements
Rank 1
Viktor asked on 18 Jul 2011, 09:59 AM
<telerik:RadGrid ID="TourGrid" runat="server" AutoGenerateColumns="false" AllowSorting="false"
                AllowMultiRowSelection="false" OnNeedDataSource="TourGrid_NeedDataSource" OnPreRender="TourGrid_PreRender"
                AllowMultiRowEdit="true" OnItemCreated="TourGrid_ItemCreated">
                <MasterTableView Width="100%" DataKeyNames="Id" EditMode="InPlace">
                    <Columns><%-- columns left out --%>
                        <telerik:GridNumericColumn DataField="NewValue" UniqueName="NewValue" HeaderText="New value"
                            ReadOnly="false" ColumnEditorID="GridNumericColumnEditor1" HeaderStyle-Width="175px"
                            DataFormatString="{0:D}" AllowRounding="false" KeepNotRoundedValue="true" DataType="System.Double" />
                    </Columns>
                </MasterTableView>
                <ClientSettings ReorderColumnsOnClient="false" AllowDragToGroup="false" AllowColumnsReorder="false"
                    AllowRowsDragDrop="false">
                    <Selecting AllowRowSelect="true" EnableDragToSelectRows="false" />
                    <Resizing AllowRowResize="true" AllowColumnResize="true" EnableRealTimeResize="true"
                        ResizeGridOnColumnResize="false" />
                    <Scrolling AllowScroll="true" UseStaticHeaders="true" FrozenColumnsCount="1" />
                    <ClientEvents />
                </ClientSettings>
            </telerik:RadGrid>
 
<telerik:GridNumericColumnEditor ID="GridNumericColumnEditor1" runat="server">
            <NumericTextBox runat="server">
                <NumberFormat NumericPlaceHolder="_" DecimalSeparator="," GroupSeparator="." KeepTrailingZerosOnFocus="true"
                    AllowRounding="false" KeepNotRoundedValue="true" />
            </NumericTextBox>
        </telerik:GridNumericColumnEditor>


I have the above grid in one of my aspx-pages.

The code-behind contains the following event handler:

protected void TourGrid_PreRender(object sender, System.EventArgs e)
        {
            if (!IsPostBack)
            {
                foreach (GridItem item in this.TourGrid.MasterTableView.Items)
                {
                    if (item is GridEditableItem)
                    {
                        GridEditableItem editableItem = item as GridDataItem;
                        editableItem.Edit = true;
                    }
                }
                this.TourGrid.Rebind();
            }
        }

This makes all the 'NewValue' fields go into edit mode when the page is loaded.

The input field should not round the values which the user enters on the page, nor should a rounded value be displayed.  With the markup above however the first row in the grid keeps the not rounded value but cuts off decimal digits after the first two.  All the other rows after the first round the value in the input box to two decimal digits and do not keep the not rounded values.

But I want the input boxes to keep the not rounded values and display all the digits of the values regardless wether the box is active (has focus) or not.  How can I achieve this?

Regards, Viktor

3 Answers, 1 is accepted

Sort by
0
Vasil
Telerik team
answered on 21 Jul 2011, 08:01 AM
Hello Viktor,

You should not use "{0:D}" as DataFormatString because this format supports integers only.
Try to use "{0:F}" Additionally you could see this resource:
http://msdn.microsoft.com/en-us/library/dwhawy9k.aspx

I hope this helps.

Kind regards,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

0
Viktor
Top achievements
Rank 1
answered on 21 Jul 2011, 08:42 AM
No that doesn't help.

The problem is that all the values except the one in the first row get rounded to two decimal digits although in the markup I specified that the input should not round values ( AllowRounding="false" KeepNotRoundedValue="true"):
<telerik:GridNumericColumn DataField="NewValue" UniqueName="NewValue" HeaderText="New value"
                            ReadOnly="false" ColumnEditorID="GridNumericColumnEditor1" HeaderStyle-Width="175px"
                            DataFormatString="{0:F}" AllowRounding="false" KeepNotRoundedValue="true" DataType="System.Double" />

I attached a screenshots wich shows the behavior.  I tried to put the same values into both fields.  The first is not rounded (as desired), but the second one gets rounded which I do not want to happen.

Regards,
Viktor
0
Accepted
Vasil
Telerik team
answered on 25 Jul 2011, 01:45 PM
Hi Viktor,

This is limitation of the column editors, please find more information in this forum thread:
http://www.telerik.com/community/forums/aspnet-ajax/grid/gridnumericcolumneditor-and-edit.aspx

Greetings,
Vasil
the Telerik team

Register for the Q2 2011 What's New Webinar Week. Mark your calendar for the week starting July 18th and book your seat for a walk through of all the exciting stuff we will ship with the new release!

Tags
Grid
Asked by
Viktor
Top achievements
Rank 1
Answers by
Vasil
Telerik team
Viktor
Top achievements
Rank 1
Share this question
or