I am trying to add a new row to RadGridView. I can add new row, BUT It doesn't allow me to enter more than 4letters in the new row. Could you check this and let me know what went wrong?
Attached screenshot.
Thank you,
-Prathibha
5 Answers, 1 is accepted
May I ask you to provide a little bit more information on how are your GridViewColumns defined, especially the first column where you can enter just 4 letters?
Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I am using MVVMLight(MvvmLightCommand) to convert event to command.
If I want to change the name of the customer or add a new customer, I can only type 4 letters in the firstName and lastName columns (eg: “asdf”) after 4th letter all text I typed are ignored.
This is my code:
View
<telerik:RadGridView ItemsSource="{Binding CustomerCollection,Mode=TwoWay,UpdateSourceTrigger=PropertyChanged}"
AutoGenerateColumns="False" Margin="5 5 5 5"
AlternationCount="2" CanUserInsertRows="True" ShowInsertRow="True"
Background="LightBlue" Name="TelerikDGrid">
<i:Interaction.Triggers>
<i:EventTrigger EventName="AddingNewDataItem">
<MvvmLightCommand:EventToCommand Command="{Binding Path=AddNewCustomerCommand}" PassEventArgsToCommand="True" />
</i:EventTrigger>
</i:Interaction.Triggers>
<telerik:RadGridView.Columns>
<telerik:GridViewMaskedTextBoxColumn Header="FistName" DataMemberBinding="{Binding FirstName}" />
<telerik:GridViewMaskedTextBoxColumn Header="LastName" DataMemberBinding="{Binding LastName}" />
CustomerClass
public class Customer : ViewModel.ViewModelBase
{
string firstName;
public string FirstName //Product
{
get { return firstName; }
set { firstName = value; NotifyPropertyChanged("FirstName"); }
}
string lastName;
public string LastName //Name
{
get { return lastName; }
set { lastName = value;NotifyPropertyChanged("LastName "); }
}
bool hasEmail;
public bool HasEmail
{
get { return hasEmail; }
set { hasEmail = value;NotifyPropertyChanged("HasEmail"); }
}
bool hasPhone;
public bool HasPhone
{
get { return hasPhone; }
set { hasPhone = value; NotifyPropertyChanged("HasPhone");}
}
}
}
ViewModel
ObservableCollection<Customer> customerCollection = new ObservableCollection<Customer>();
public ObservableCollection<Customer> CustomerCollection
{
get { return customerCollection; }
set { customerCollection = value; NotifyPropertyChanged("CustomerCollection"); }
}
#region Constructor
public ViewModel()
{
AddNewCustomerCommand = new RelayCommand(Execute_AddNewCustomerCommand, CanExecute_AddNewCustomerCommand);
}
#endregion
#region AddNewCustomerCommand
public ICommand AddNewCustomerCommand { get; private set; }
public void Execute_AddNewCustomerCommand(object e)
{
Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs args = (Telerik.Windows.Controls.GridView.GridViewAddingNewEventArgs)e;
args.NewObject = new Customer();
}
public bool CanExecute_AddNewCustomerCommand(object parameter)
{
return true;
}
#endregion
Thank you,
-Prathibha
I would suggest you to use GridViewDataColumn instead. May I ask you is there a special reason to use GridViewMaskedTextBoxColumn?
Regards,Didie
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.
I wanted to use GridViewMaskedTextBoxColumn for the look and feel(the GridViewMaskedTextBoxColumn looks non-editable but allow the user edit it when clicked on the TextBoxColumn) . I also wanted to make the FirstColumn(FirstName) read only, but allow the user to add new row.(ie user cannot edit existing columns.Allow the user to add new row and add attributes,but once he commit the change by enter key, that column should be ReadOnly.)
Thank you,
-Prathibha
As Didie mentioned - GridViewDataColumn is the good choice for your case - By default it displays a TextBlock , and when being edited it would display a TextBox.
Regarding your second question - you can prevent the "old" rows from entering edit mode the following way :
1. Subscribe to the RadGridView.BeginningEdit event
2. Inside the event handler check if it is old or new row
3. In case it is an "old" row set e.Cancel = true .
All the best,
Pavel Pavlov
the Telerik team
Explore the entire Telerik portfolio by downloading Telerik DevCraft Ultimate.