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

RadDataForm Enable/Disable Add/Edit/Delete?

17 Answers 802 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
Brian
Top achievements
Rank 1
Brian asked on 04 Oct 2011, 02:49 PM
Is there a way to set a RadDataForm to read-only and either hide or disable the add/edit/delete buttons?  I need to enable or disable the ability of the user to edit data on the form at runtime.

17 Answers, 1 is accepted

Sort by
0
Ivan Ivanov
Telerik team
answered on 04 Oct 2011, 03:18 PM
Hi Brian,

Try setting RadDataForm's CommandButtonsVisibility property to "Navigation". In this way you will hide all the commands buttons, except for these from the navigation panel.

All the best,
Ivan Ivanov
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
0
Brian
Top achievements
Rank 1
answered on 04 Oct 2011, 03:50 PM
Ivan,
Thanks, that works for me.
0
s2uiguy
Top achievements
Rank 1
answered on 18 Nov 2011, 12:14 AM
Is there a way to set just Edit, Commit, and Cancel???
Thanks!
0
Maya
Telerik team
answered on 18 Nov 2011, 01:23 PM
Hello Bobby,

Generally, the visibility of 'Add'/ 'Delete' buttons depends on the data source collection and whether it supports inserting/ removing items. If your collection allows you to add/delete items, but you still want to remove the buttons, you can edit the template of RadDataForm and remove those buttons that you do not want to be displayed.
 

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>

0
Jeff
Top achievements
Rank 1
answered on 25 Jan 2012, 09:53 PM
I find this kind of answer to be enormously frustrating.

I am currently banging my head against the wall, trying to get add/delete buttons to show up in a WPF RadDataForm, and browsing the web brought me to this answer.

"Generally, the visibility of 'Add'/ 'Delete' buttons depends on the data source collection and whether it supports inserting/ removing items."

Great.  Which data source collections support inserting/removing items?  What specifically is RadDataForm looking for, when it decides whether the bound collection supports inserting/removing items?  Is it looking for whether the collection implements specific interfaces?  Implements specific methods?  Handles specific events?

And where is this documented? Where do I go, in the documentation, to determine what I need in my collection to trigger specific behaviors in the control?
0
Dempsey
Top achievements
Rank 1
answered on 01 Dec 2012, 12:15 AM
Gee, I completely agree with this comment.
>> I find this kind of answer to be enormously frustrating.
I've spent nearly 2 hours now on your site trying to figure out how to get my Delete icon to activate in my RadDataForm. I finally thought I had found the answer, but then I too find that I am given only a hint and no answer. This is indeed enormously frustrating! And it's not just this answer but many answers found on here. Is it possible, Maya, to provide the missing information?


0
Maya
Telerik team
answered on 03 Dec 2012, 08:54 AM
Hello Dempsey,

I am really sorry to see that you have troubles working with RadDataForm and its documentation. We will do our best to improve it and add article concerning inserting, deleting, canceling editing, etc.
Actually, RadDataForm works as an items control - if the collection itself supports insert/ delete functionality (has Add/Remove methods for example), it will invoke them and add or remove an item. That is why we did not introduce article explaining such scenarios.
However, in order to avoid any frustration from now on, we will try to improve the documentation. Let me know in case you have other problems with it so that we can make it better.

Kind regards,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Dempsey
Top achievements
Rank 1
answered on 11 Dec 2012, 11:32 PM
Hi, Maya.
Thank you for your reply. After all this time, I'm still unable to get the Delete icon (the trashcan) to be enabled on my RadDataForm. You guys told us that:

>> Generally, the visibility of 'Add'/ 'Delete' buttons depends on the data source collection
>> and whether it supports inserting/ removing items.

What's a bit frustrating is that information seems fairly hard to figure out. I myself am using an ICollection View, and in other parts of my program (a child window), I can select an item and then punch a button that caused that item to be added to the ICollection. So it appears to me that my data source collection does indeed "supports inserting/removing items." Still, though, the Delete icon never becomes enabled.

In  my dataform, I have the following Command Buttons Visibility settings:

>>   CommandButtonsVisibility="Cancel, Commit, Edit, Delete, Navigation"

Since the Delete icon never becomes enabled, I'm sure I'm doing something wrong, and *perhaps* it is that my collection type doesn't truly meet the criteria you mentioned. I think what Jeff was referring to, and what I agreed with, is that your previous answer seems to provide only a "clue" to an answer but not a thorough answer. In particular, for this situation, how do I know if ICollection truly "supports inserting/removing items?" Furthermore, what *other* collections would/would-not quality for turning on the Delete capability for a RadDataForm? Having that information would make for a great, complete, non-frustrating answer.

Just a suggestion...
Dempsey
0
Maya
Telerik team
answered on 12 Dec 2012, 08:51 AM
Hi,

The article for Add, Edit and Delete functionality of RadDataForm in already available in our documentation.
Considering the frustration that you have, the behavior of the data form is just as any other items control. So, if you are able to add/ remove items from a DataGrid for example, you will be able to do that in the form as well.
Nevertheless, I would recommend you to run through this article and its subsequent ones for more information on different types of collections and the functionality they provide.    

Greetings,
Maya
the Telerik team

Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.

0
Tim
Top achievements
Rank 1
answered on 16 Jul 2013, 09:33 PM
I'm having a similar issue with RadDataForm (RadControls for Silverlight Q2 2013). The add Add New Item button is disabled. However, the ItemSource is an ObservableCollection, which supports the Add method. Also, this code was working at some point before upgrading to Q2 2013. However, I might have done something else to make this break, any suggestions?

Thanks
Tim

AdminViewModel.cs:

public ObservableCollection<EditableContact> Contacts
        {
            get { return contacts ?? (contacts = new ObservableCollection<EditableContact>()); }
            set { Set("Contacts"ref contactsvalue); }
        }

View.xaml:
DataContext="{Binding AdminViewModel, Source={StaticResource Locator}}">

<DataTemplate x:Key="ContactsTemplate">
            <Grid HorizontalAlignment="Stretch" VerticalAlignment="Stretch" Margin="5,15,5,5" Background="WhiteSmoke">
                <Grid.ColumnDefinitions>
                    <ColumnDefinition />
                </Grid.ColumnDefinitions>
                <Grid.RowDefinitions>
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                    <RowDefinition />
                </Grid.RowDefinitions>
                <telerik:DataFormDataField Grid.Row="0" Label="Company:"
                                           DataMemberBinding="{Binding Company, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Row="1" Label="Name:" DataMemberBinding="{Binding Name, Mode=TwoWay}" />
                <telerik:DataFormComboBoxField Grid.Row="2" Label="Type:"
                                               ItemsSource="{Binding DataContext.ContactTypes, ElementName=LayoutRoot}"
                                               DataMemberBinding="{Binding Type, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Row="3" Label="Email:" DataMemberBinding="{Binding Email, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Row="4" Label="Phone1:"
                                           DataMemberBinding="{Binding Phone1, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Row="5" Label="Phone2:"
                                           DataMemberBinding="{Binding Phone2, Mode=TwoWay}" />
                <telerik:DataFormDataField Grid.Row="6" Label="Extension:"
                                           DataMemberBinding="{Binding Extension, Mode=TwoWay}" />
 
                <telerik:DataFormDataField Grid.Row="7" Label="Notes:" DataMemberBinding="{Binding Notes, Mode=TwoWay}" />
                
            </Grid>
        </DataTemplate>

<telerik:RadDataForm x:Name="EditContactsForm" AutoGenerateFields="False" Margin="3,3,3,3"  
                                     Header="Edit Contacts" ItemsSource="{Binding Contacts }"
                                     ReadOnlyTemplate="{StaticResource ContactsTemplate}"
                                     EditTemplate="{StaticResource ContactsTemplate}"
                                     NewItemTemplate="{StaticResource ContactsTemplate}"
                                     >
                </telerik:RadDataForm>

Model: 
public class EditableContact : ContactIEditableObject

0
Maya
Telerik team
answered on 17 Jul 2013, 06:34 AM
Hi Tim,

Will it be possible to verify whether you have a default parameterless constructor for your business object ?  

Regards,
Maya
Telerik
TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for SILVERLIGHT.
Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
Sign up for Free application insights >>
0
Tom
Top achievements
Rank 1
answered on 23 Jul 2015, 12:29 AM
This has to be the worst response to what should be a simple answer, why don't you provide an example of how to get the DELETE button to show up?  You keep responding like a robot, we wan't straight answers without having to be told by the SUPPORT team that we pay to go read an article when the answer is probably something rather simple.  Why don't you provide an example.
0
Maya
Telerik team
answered on 23 Jul 2015, 02:25 PM
Hi Brian,

We provide multiple example where Delete button is enabled and you can refer to our Demos as well as our SDK browser. Once DataForm is bound to a source collection that supports Remove functionality, the Delete button will be enabled. 
Do you have some specific scenario with custom collection or anything else that does not support removing the items ? 


Regards,
Maya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Jeff
Top achievements
Rank 1
answered on 23 Jul 2015, 02:43 PM

It's been a few years since I posted my complaints in this thread. I am not, in fact, using Telerik controls any longer, except while maintaining what are now legacy apps.  (No complaint against Telerik, in particular, it's just we're no longer writing asp.net websites).

 

My complaint is simply that the documentation is incomplete.

Take this "explanation", as an example:

 

"if the collection itself supports insert/ delete functionality (has Add/Remove methods for example), it will invoke them and add or remove an item."

 

That is a meaningless remark. The collection isn't capable of determining whether the collection supports insert/delete functionality. All it can do is use reflection to examine the properties and methods that are available on the collection. It might see a method Insert(), and assume that the collection supports inserts. Or it might not see a method Insert(), and though there is a method insert(), that doesn't match what it's looking for so it assumes that it doesn't support inserts.

 The logic within the control by which it determines whether a collection supports insert or delete isn't documented. What methods need to be present in the collection for the control to decide whether it can do inserts? Whether it can do deletes? These should be explicitly documented, and the last time I went through the documentation, they weren't.

 

 

0
Maya
Telerik team
answered on 27 Jul 2015, 08:27 AM
Hello Jeff,

Thanks for the feedback, we will take care for updating the documentation so that it contains more information about the ability to insert/ delete items. 
And in order to shed some more light in this thread, I will provide a bit more explanations. 

Insert operation is enabled or disabled based on the CanAddItems property of RadDataForm. It is set like:
private void SetCanAddItems()
    {
        this.CanAddItems = this.ItemsSource != null && this.FormViewModel.Items.CanAddNew && !this.IsAddingNew &&  his.CanExecuteWhenAutoCommitFalse();
    }

So, it needs ItemsSource and to verify that you are not adding items at the moment. CanAddNew of the Items collection depends on the CanAddNew property of the EditableCollectionView of the source. The last method returns:
private bool CanExecuteWhenAutoCommitFalse()
{
    return this.AutoCommit ? true : !this.HasChangesToCommit;
}

AutoCommit is the corresponding property of the data form, HasChangesToCommit evaluates the modifications made.

Considering delete command, it depends on CanDeleteItems property of the data form:
private void SetCanDeleteItems()
        {
            this.CanDeleteItems = this.ItemsSource != null && this.FormViewModel.Items.Count != 0 && this.FormViewModel.Items.CanRemove && !this.IsAddingNew;
        }

I guess its elements speak for themselves.

In case there is some misunderstanding or something is not clear enough, I will be happy to provide the missing information. 



Regards,
Maya
Telerik
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
0
Srinu
Top achievements
Rank 1
answered on 19 Dec 2016, 03:53 PM

Hello Maya,

The CommitButton is always disabled in the RadDataForm popup window. Can you pls see below code example and suggest how to fix it?

 

<Grid>
      <Grid.ColumnDefinitions>
          <ColumnDefinition Width="*" />
      </Grid.ColumnDefinitions>
      <Grid.RowDefinitions>
          <RowDefinition Height="25" />
          <RowDefinition Height="*" />
      </Grid.RowDefinitions>

     <telerik:Label Grid.Row="0" Content="Indexes" FontWeight="Bold" BorderBrush="Gray" BorderThickness="0 0 0 1" />
      <telerik:RadGridView
           Name="radgrdEntityIndexes"
           ItemsSource="{Binding IndexesList}"
           AutoGenerateColumns="False"
           RowIndicatorVisibility="Collapsed"
           GridLinesVisibility="Horizontal"
           FrozenColumnsSplitterVisibility="Hidden"
           CanUserDeleteRows="False"
           CanUserInsertRows="False"
           CanUserSelect="False"
           EnableColumnVirtualization="True"
           EnableRowVirtualization="True"
           HorizontalAlignment="Stretch"
           VerticalAlignment="Stretch"
           ShowSearchPanel="False"
           ShowGroupPanel="False"
           ScrollViewer.HorizontalScrollBarVisibility="Auto"
           ScrollViewer.VerticalScrollBarVisibility="Auto"
           Grid.Row="2">
     <telerik:RadContextMenu.ContextMenu>
           <telerik:RadContextMenu x:Name="GridContextMenu" ItemClick="GridContextMenu_ItemClick">
                 <telerik:RadContextMenu.Items>
<telerik:RadMenuItem Header="Add New Index" Tag="Add" />
<telerik:RadMenuItem Header="Edit" Tag="Edit" />
<telerik:RadMenuItem Header="Delete" Tag="Delete"/>
                 </telerik:RadContextMenu.Items>
           </telerik:RadContextMenu>
     </telerik:RadContextMenu.ContextMenu>
     <telerik:RadGridView.Columns>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding IndexTableName}" Header="Table Name" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding IndexType}" Header="Index Type" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding IndexColumn}" Header="Column Name" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding IndexSortOrder}" Header="Sort Order" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding IndexColSequence}" Header="Column Sequence" IsReadOnly="True"/>
          <telerik:GridViewCheckBoxColumn DataMemberBinding="{Binding IsIncluded}" Header="Is Included" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding EntityId}" Header="Entity Id" IsReadOnly="True" IsVisible="False" />
          <telerik:GridViewDataColumn DataMemberBinding="{Binding EntityName}" Header="Entity Name" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding CreateUserName}" Header="Create User" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding CreateDate}" Header="Create Date" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding UpdateUserName}" Header="Update User" IsReadOnly="True"/>
          <telerik:GridViewDataColumn DataMemberBinding="{Binding UpdateDate}" Header="Update Date" IsReadOnly="True"/>
     </telerik:RadGridView.Columns>
     </telerik:RadGridView>                                   
</Grid>


<Grid Visibility="Hidden">
    <Grid.Resources>
         <DataTemplate x:Key="IndexesDataFormTemplate">
             <Grid Margin="5,5,5,5">
                  <Grid.ColumnDefinitions>
<ColumnDefinition Width="200" />
<ColumnDefinition Width="250" />
                  </Grid.ColumnDefinitions>
                  <Grid.RowDefinitions>
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
                       <RowDefinition Height="5" />
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
<RowDefinition Height="5" />
<RowDefinition Height="25" />
                  </Grid.RowDefinitions>

                  <telerik:Label Grid.Row="0" Content="Index table Name:"></telerik:Label>
                  <telerik:RadComboBox x:Name="radComboboxIndexTableName" Grid.Column="1" Grid.Row="0" />
                  <telerik:Label Grid.Row="2" Content="Index Type:"></telerik:Label>
                  <telerik:RadComboBox x:Name="radComboboxIndexType" Grid.Column="1" Grid.Row="2" />
                  <telerik:Label Grid.Row="4" Content="Index Column:"></telerik:Label>
                  <TextBox x:Name="radTextboxTableColumnName" Grid.Column="1" Grid.Row="4" SpellCheck.IsEnabled="True" />
                  <telerik:Label Grid.Row="6" Content="Index Column Sort Order:"></telerik:Label>
                  <TextBox x:Name="radTextboxTableColumnSortOrder" Grid.Column="1" Grid.Row="6" SpellCheck.IsEnabled="True" PreviewTextInput="radTextboxTableColumnSortOrder_PreviewTextInput" />
                  <telerik:Label Grid.Row="8" Content="Index Column Sequence:"></telerik:Label>
                  <TextBox x:Name="radTextboxTableColumnSequence" Grid.Column="1" Grid.Row="8" SpellCheck.IsEnabled="True" PreviewTextInput="radTextboxTableColumnSequence_PreviewTextInput" />
                  <telerik:Label Grid.Row="10" Content="Is Included:"></telerik:Label>
                  <CheckBox x:Name="radCheckboxIsIncluded" Grid.Column="1" Grid.Row="10" />
                  <telerik:Label Grid.Row="12" Content="Index table Name:"></telerik:Label>
                  <telerik:RadComboBox x:Name="radComboboxEntity" Grid.Column="1" Grid.Row="12" />
            </Grid>
       </DataTemplate>
   </Grid.Resources>
   <telerik:RadDataForm x:Name="radDataFormIndexes"
          ReadOnlyTemplate="{StaticResource IndexesDataFormTemplate}"
          EditTemplate="{StaticResource IndexesDataFormTemplate}"
          CommandButtonsVisibility="Navigation"
          CommitButtonContent="Save" />
</Grid>


private void GridContextMenu_ItemClick(object sender, Telerik.Windows.RadRoutedEventArgs e)
        {
            if (this.radDataFormIndexes.Parent is Grid)
            {
                var parent = (Grid)this.radDataFormIndexes.Parent;
                parent.Children.Remove(this.radDataFormIndexes);
            }

            var row = ((RadContextMenu)sender).GetClickedElement<Telerik.Windows.Controls.GridView.GridViewRow>();
            var dataContext = (Palms3.Module.Metadata.MACWorkFlow.ViewModels.EntityDetailViewModel)this.DataContext;

            RadWindow radWindowIndexes = new RadWindow();
            radWindowIndexes.Content = this.radDataFormIndexes;
            radWindowIndexes.Height = 500;
            radWindowIndexes.Width = 600;
            radWindowIndexes.HideMinimizeButton = true;
            radWindowIndexes.HideMaximizeButton = true;
            radWindowIndexes.WindowStartupLocation = WindowStartupLocation.CenterScreen;

            switch ((e.OriginalSource as RadMenuItem).Tag.ToString())
            {
                case "Add":
                    radWindowIndexes.Header = "Add New Index";
break;
                case "Edit":
                    radWindowIndexes.Header = "Edit Index";
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexTableName")).ItemsSource = dataContext.MetadataTableNames;
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexTableName")).SelectedValue = ((Indexes)row.Item).IndexTableName;

                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexType")).ItemsSource = dataContext.IndexTypes;
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexType")).DisplayMemberPath = "IndexType";
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexType")).SelectedValuePath = "IndexType";
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxIndexType")).SelectedValue = ((Indexes)row.Item).IndexType;

                    (FindControl<TextBox>(radDataFormIndexes, "radTextboxTableColumnName")).Text = ((Indexes)row.Item).IndexColumn;
                    (FindControl<TextBox>(radDataFormIndexes, "radTextboxTableColumnSortOrder")).Text = ((Indexes)row.Item).IndexColSortOrder;
                    (FindControl<TextBox>(radDataFormIndexes, "radTextboxTableColumnSequence")).Text = ((Indexes)row.Item).IndexColSequence.ToString();
                    (FindControl<CheckBox>(radDataFormIndexes, "radCheckboxIsIncluded")).IsChecked = ((Indexes)row.Item).IsIncluded;

                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxEntity")).ItemsSource = dataContext.EntitiesList;
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxEntity")).DisplayMemberPath = "EntityName";
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxEntity")).SelectedValuePath = "EntityId";
                    (FindControl<RadComboBox>(radDataFormIndexes, "radComboboxEntity")).SelectedValue = ((Indexes)row.Item).EntityId;

                    radWindowIndexes.Content = this.radDataFormIndexes;
                    radDataFormIndexes.BeginEdit();
break;
                default:
                    break;
            }

            radWindowIndexes.ShowDialog();
            radWindowIndexes.Focus();
        }

        private List<Control> AllChildren(DependencyObject parent)
        {
            var _List = new List<Control>();

            for (int i = 0; i < System.Windows.Media.VisualTreeHelper.GetChildrenCount(parent); i++)
            {
                var _Child = System.Windows.Media.VisualTreeHelper.GetChild(parent, i);

                if (_Child is Control)
                {
                    _List.Add(_Child as Control);
                }

                _List.AddRange(AllChildren(_Child));
            }
            return _List;
        }

        private T FindControl<T>(DependencyObject parentContainer, string controlName)
        {
            var childControls = AllChildren(parentContainer);
            var control = childControls.OfType<Control>().Where(x => x.Name.Equals(controlName)).Cast<T>().First();
            return control;
        }

0
Stefan Nenchev
Telerik team
answered on 21 Dec 2016, 10:33 AM
Hello ,

It is hard for us to guess what the exact reason of the issue is based on the information you have provided. Please raise a ticket with a sample project or a more detailed explanation of your scenario so we can investigate it from our side. 

Regards,
Stefan Nenchev
Telerik by Progress
Try our brand new, jQuery-free Angular 2 components built from ground-up which deliver the business app essential building blocks - a grid component, data visualization (charts) and form elements.
Tags
DataForm
Asked by
Brian
Top achievements
Rank 1
Answers by
Ivan Ivanov
Telerik team
Brian
Top achievements
Rank 1
s2uiguy
Top achievements
Rank 1
Maya
Telerik team
Jeff
Top achievements
Rank 1
Dempsey
Top achievements
Rank 1
Tim
Top achievements
Rank 1
Tom
Top achievements
Rank 1
Srinu
Top achievements
Rank 1
Stefan Nenchev
Telerik team
Share this question
or