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

ShowAddNewRecordButton in DetailTables

1 Answer 194 Views
Grid
This is a migrated thread and some comments may be shown as answers.
Martin
Top achievements
Rank 1
Martin asked on 28 Nov 2011, 06:29 PM
I have several RadGrids which I'm modifying programatically so that....
 
If the user clicks "Edit", ShowAddNewRecordButton is set to 'False' and I rebind the grid.
If the user clicks "Add New Record", e.Item.Edit is set to 'False' and I rebind the grid.

In effect, this means that the user cannot access the 'edit' and 'add new' forms at the same time.  Only one can ever be open.  I do this for a couple of reasons. 

Firstly, if the user tries to add a record AND edit a record (both the 'add new' and 'edit' forms are open simultaneously), if the user tries to submit the edited record first, the validation on the 'add new record' form fires - preventing the edit from occuring. 

Secondly, I have controls which I want to appear when the user adds a new record, but I want hidden when they edit a record.  I've been able to program the grid to hide the controls If the user edits a record, BUT if the user edits a record THEN clicks the 'adds new' button (whilst the edit form is still expanded), the controls show in both the add new AND - unfortunately - the edit forms.

By controlling access to the "Edit" and "Add New" forms so only one can be open at any one time, this resolves the above issues.  Unfortunately, I have a DetailTable which I'm also trying to program to behave the same way but I don't know how to reference the ShowAddNewRecordButton value when it's within a DetailTable.  Also, when I rebind the grid, it loses the expanded row (which you'd expect).  Any ideas?  My code is below...

Protected Sub rdgRiskType_ItemCommand(ByVal sender As Object, ByVal e As Telerik.Web.UI.GridCommandEventArgs) Handles rdgRiskType.ItemCommand

    'If user inserts a new Risk Type record, set 'edit' mode to false and rebind (all 'edit' forms will be minimised).
    If e.CommandSource.Text = "Add New Risk Type" Then
        e.Item.Edit = False
        rdgRiskType.Rebind()
    End If

    'If user edits a Risk Type record, hide the 'Add New xxx' button (user can't then add a new record whilst an edit form is maximised).
    If e.CommandSource.Text = "Edit" Then
        rdgRiskType.MasterTableView.CommandItemSettings.ShowAddNewRecordButton = False
        rdgRiskType.MasterTableView.IsItemInserted = False
        rdgRiskType.Rebind()
    End If

    'If user inserts a new Risk record, set 'edit' mode to false and rebind (all 'edit' forms will be minimised).
    If e.CommandSource.Text = "Add New Risk" Then

    End If

    'If user edits a Risk record, hide the 'Add New xxx' button (user can't then add a new record whilst an edit form is maximised).
    If e.CommandSource.Text = "Edit Risk" Then

    End If

End Sub

1 Answer, 1 is accepted

Sort by
0
Antonio Stoilkov
Telerik team
answered on 01 Dec 2011, 04:45 PM
Hi Martin,

You could clear all opened items for edit by calling either rdgRiskType.MasterTableView.ClearEditItems() or rdgRiskType.EditIndexes.Clear(). Additionally, you could clear them on a GridTableView level by calling e.Item.OwnerTableView.ClearEditItems(). 

Accessing the ShowAddNewRecordButton requires only the index of the DetailTable and can be done by calling rdgRiskType.MasterTableView.DetailTables[detailTableIndex].CommandItemSettings.ShowAddNewRecordButton = false. You could also try not calling the Rebind() method and see if the application continues running as expected.

Best wishes,
Antonio Stoilkov
the Telerik team
If you want to get updates on new releases, tips and tricks and sneak peeks at our product labs directly from the developers working on the RadControls for ASP.NET AJAX, subscribe to their blog feed now
Tags
Grid
Asked by
Martin
Top achievements
Rank 1
Answers by
Antonio Stoilkov
Telerik team
Share this question
or