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

Edit Mode Resets Column Editors

3 Answers 106 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 01 Jan 2011, 03:16 AM
I have a scenario in which I have a RadGrid with in-place editing enabled. Several of the columns have custom editors referenced by the ColumnEditorID attribute, and all of the column editors in the grid are Telerik controls. I am catching the ItemCommand event in the code-behind to process the grid commands. The AllowMultiRowEdit attribute of the grid is set to false.

If I click Edit on one of the rows, the row goes into Edit mode correctly, and all of the formatting rules for each column editor are respected (e.g. I have a currency column that displays with a dollar sign and two decimal places, an integer column that displays with no decimal places and no commas, and the numeric columns are aligned right). Now, if I click Edit on a different row, the row that was previously in Edit mode exits edit mode and the second row that was clicked goes into Edit mode, again, as expected. However, the column editors in the second row have now lost the formatting rules. The currency column displays with no dollar sign, the integer column displays with decimal places and commas, and the numeric columns are no longer aligned right.

Note that the formatting is only lost on the editors themselves. The cells, when in view mode, retain their appropriate formatting.

Here is my grid:

<telerik:RadGrid
                                ID="grdChecksIssued" runat="server" GridLines="None"
                                AllowPaging="True" AllowAutomaticUpdates="true"
                                AllowAutomaticDeletes="True" AllowAutomaticInserts="false"
                                AllowSorting="True" AutoGenerateColumns="False" AllowMultiRowEdit="false">
                                <headercontextmenu cssclass="GridContextMenu GridContextMenu_Default"
                                    enableimagesprites="True">
                                </headercontextmenu>
                                <mastertableview CommandItemDisplay="Top" AllowSorting="true" TableLayout="Fixed"
                                    CommandItemSettings-AddNewRecordText="Add Issued Check"
                                    AllowMultiColumnSorting="false" EditMode="InPlace"
                                    InsertItemDisplay="Bottom" AutoGenerateColumns="false"
                                    NoMasterRecordsText="No checks issued today.">
                                    <commanditemsettings ShowRefreshButton="False" />
                                    <Columns>
                                        <telerik:GridButtonColumn CommandName="Delete" Text="Delete" UniqueName="DeleteColumn">
                                            <HeaderStyle Width="50px" />
                                        </telerik:GridButtonColumn>
                                        <telerik:GridEditCommandColumn UniqueName="EditCommandColumn1" UpdateText="Save" InsertText="Save">
                                            <HeaderStyle Width="50px" />
                                            <ItemStyle cssclass="EditColumn" />
                                        </telerik:GridEditCommandColumn>
                                        <telerik:GridNumericColumn DataField="PPIssuedID" DataType="System.Int64"
                                            HeaderText="PPIssuedID" SortExpression="PPIssuedID"
                                            UniqueName="PPIssuedID" Visible="False">
                                        </telerik:GridNumericColumn>
                                        <telerik:GridNumericColumn DataField="UserID" DataType="System.Int64"
                                            HeaderText="UserID" SortExpression="UserID"
                                            UniqueName="UserID" Visible="False">
                                        </telerik:GridNumericColumn>
                                        <telerik:GridDropDownColumn DataField="AcctNo" DataType="System.Int64"
                                            HeaderText="Account" SortExpression="AcctNo" DataSourceID="odsPPAccounts"
                                            UniqueName="AcctNo" DropDownControlType="RadComboBox" ListTextField="DisplayNameAcct"
                                            ListValueField="AcctNo">
                                            <HeaderStyle Width="140px" />
                                            <ItemStyle CssClass="AcctNoColumn" />
                                        </telerik:GridDropDownColumn>
                                        <telerik:GridNumericColumn DataField="SerialNo" DataType="System.Int32" ColumnEditorID="gceSerialNo"
                                            HeaderText="Serial No." SortExpression="SerialNo" UniqueName="SerialNo">
                                            <HeaderStyle HorizontalAlign="Right" Width="75px" />
                                            <ItemStyle HorizontalAlign="Right" cssclass="SerialNoColumn" />
                                        </telerik:GridNumericColumn>
                                        <telerik:GridDateTimeColumn DataField="WriteDate" HeaderText="Write Date"
                                            SortExpression="WriteDate" UniqueName="WriteDate" DataFormatString="{0:MM/dd/yyyy}"
                                            DataType="System.DateTime" ColumnEditorID="gceWriteDate">
                                            <HeaderStyle Width="100px" />
                                        </telerik:GridDateTimeColumn>
                                        <telerik:GridNumericColumn DataField="Amount" HeaderText="Amount" ShowSortIcon="true"
                                            SortExpression="Amount" UniqueName="Amount" DataType="System.Decimal"
                                            NumericType="Currency" ColumnEditorID="gceAmount">
                                            <HeaderStyle Width="95px" HorizontalAlign="Right" />
                                            <ItemStyle HorizontalAlign="Right" CssClass="AmountColumn" />
                                        </telerik:GridNumericColumn>
                                        <telerik:GridBoundColumn DataField="Payee" HeaderText="Payee" ColumnEditorID="gcePayee"
                                            SortExpression="Payee" UniqueName="Payee" AllowSorting="true">
                                            <ItemStyle CssClass="IssCheckPayee" />
                                        </telerik:GridBoundColumn>
                                        <telerik:GridCheckBoxColumn DataField="IsVoid" DataType="System.Boolean"
                                            HeaderText="Void" SortExpression="IsVoid" UniqueName="IsVoid">
                                            <HeaderStyle Width="65px" />
                                        </telerik:GridCheckBoxColumn>
                                    </Columns>
                                </mastertableview>
                            </telerik:RadGrid>
                            <telerik:GridNumericColumnEditor ID="gceSerialNo" runat="server">
                                <NumericTextBox ID="NumericTextBox1" runat="server" MaxLength="10" MinValue="0" Width="45px">
                                    <NumberFormat DecimalDigits="0" GroupSeparator="" DecimalSeparator=" " />
                                    <EnabledStyle HorizontalAlign="Right" />
                                </NumericTextBox>
                            </telerik:GridNumericColumnEditor>
                            <telerik:GridNumericColumnEditor ID="gceAmount" runat="server">
                                <NumericTextBox ID="NumericTextBox2" runat="server" MinValue="0" MaxValue="999999999999999.99">
                                    <NumberFormat DecimalDigits="2" KeepTrailingZerosOnFocus="true"
                                        PositivePattern="$n" />
                                    <EnabledStyle HorizontalAlign="Right" Width="65px" />
                                </NumericTextBox>
                            </telerik:GridNumericColumnEditor>
                            <telerik:GridDateTimeColumnEditor ID="gceWriteDate" runat="server">
                                <TextBoxStyle Width="90px" />
                            </telerik:GridDateTimeColumnEditor>
                            <telerik:GridTextBoxColumnEditor ID="gcePayee" runat="server">
                                <TextBoxStyle Width="100px" />
                            </telerik:GridTextBoxColumnEditor>
                            <asp:ObjectDataSource ID="odsPPAccounts" runat="server"
                                DataObjectTypeName="clsDDA" SelectMethod="GetPPAccounts"
                                TypeName="WebLinks.PosPayMain" />

And here is my code-behind:

Private Sub grdChecksIssued_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles grdChecksIssued.ItemCommand
        Select Case e.CommandName
            Case RadGrid.InitInsertCommandName
                grdChecksIssued.MasterTableView.ClearEditItems()
            Case RadGrid.EditCommandName
                grdChecksIssued.MasterTableView.IsItemInserted = False
            Case RadGrid.PerformInsertCommandName, _
                 RadGrid.UpdateCommandName
                SaveRow(e.Item)
            Case RadGrid.DeleteCommandName
                Dim hshCells As New Hashtable()
                CType(e.Item, GridDataItem).ExtractValues(hshCells)
                DeleteRow(hshCells)
        End Select
    End Sub
 
    Private Sub grdChecksIssued_NeedDataSource(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridNeedDataSourceEventArgs) Handles grdChecksIssued.NeedDataSource
        grdChecksIssued.DataSource = GetRows()
    End Sub

Any help would be greatly appreciated.

Thanks!

3 Answers, 1 is accepted

Sort by
0
Accepted
Princy
Top achievements
Rank 2
answered on 03 Jan 2011, 06:49 AM
Hello Josh,

One suggestion is to try setting the same formatting options for the column editors in the code behind like below.

C#:
protected void grdChecksIssued_ItemDataBound(object sender, GridItemEventArgs e)
   {
       if (e.Item is GridEditableItem && e.Item.IsInEditMode)
       {
           GridEditableItem item = (GridEditableItem)e.Item;
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.MaxLength = 10;
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.MinValue = 0;
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.Width = Unit.Pixel(45);
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.NumberFormat.DecimalDigits = 0;
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.NumberFormat.GroupSeparator = "";
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.NumberFormat.DecimalSeparator= " ";
           (item.EditManager.GetColumnEditor("SerialNo") as GridNumericColumnEditor).NumericTextBox.EnabledStyle.HorizontalAlign = HorizontalAlign.Right;
        }
   }

Thanks,
Princy.
0
Josh
Top achievements
Rank 1
answered on 03 Jan 2011, 03:43 PM
This worked perfectly. Is the ItemDataBound event the preferred place to apply formatting rules to a grid in general, rather than at design time?
0
Michael
Top achievements
Rank 1
answered on 24 Oct 2011, 10:30 PM
This sounds like it might actually be a bug in the grid.  It doesn't make a lot of sense to have to repeat all my editor settings in the event that I have in the markup.  In any event, I can also confirm that this does make it work... I just can't say this "fixes it".
Tags
Grid
Asked by
Josh
Top achievements
Rank 1
Answers by
Princy
Top achievements
Rank 2
Josh
Top achievements
Rank 1
Michael
Top achievements
Rank 1
Share this question
or