17 Answers, 1 is accepted
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
Thanks, that works for me.
Thanks!
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading the Ultimate Collection trial package. Get it now >>
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?
>> 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?
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
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
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.
Maya
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
Thanks
Tim
AdminViewModel.cs:
public ObservableCollection<EditableContact> Contacts { get { return contacts ?? (contacts = new ObservableCollection<EditableContact>()); } set { Set("Contacts", ref contacts, value); } }
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 : Contact, IEditableObject
Will it be possible to verify whether you have a default parameterless constructor for your business object ?
Maya
Telerik
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 >>
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
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.
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
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;
}
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