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

[Solved] BeginEdit, AddNew, Mode

5 Answers 246 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
This question is locked. New answers and comments are not allowed.
Francois Vanderseypen
Top achievements
Rank 2
Francois Vanderseypen asked on 30 Mar 2011, 02:21 PM
The dataform sits in a Page and when OnNavigatedTo is called the following calls do not have any effect:

PersonForm.Mode=RadDataFormMode.Edit;
PersonForm.AddNewItem();
PersonForm.BeginEdit;

I'm probably overlooking the totally obvious.

Thx, Fr.

PS: using the RadDomainDataSource to set the CurrentItem on the form.

5 Answers, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 30 Mar 2011, 03:18 PM
Hello Francois Vanderseypen,

Depending on what is the source object/collection , you may or may not be able to enter edit mode.
Please give me more details about the data bound to RadDataForm so I can isolate what may be gone wrong.

All the best,
Pavel Pavlov
the Telerik team
0
Marco Teodoro
Top achievements
Rank 1
answered on 26 Apr 2011, 12:23 PM
hello.

I have the same problem, i have a view that i will open on read or new itemmode.

But in bought cases i will assign the CurrentItem  property to one viewmodel property.

How can i enter on read or edit mode?

i also need to have the buttons, Change mode from read to edit,

begin edit, cancel edit, endedit. 

I want to wrap a new instance of the object on viewmodel to be able to cancel the edition.

I don't want to use IEditable object because my Entities simple poco objects... and they need to continue like this.

0
Pavel Pavlov
Telerik team
answered on 29 Apr 2011, 10:11 AM
Hello Marco Teodoro,

RadDataForm may work with a single object( given trough the current item property) and with a collection of objects ( given trough  the ItemsSource property) .

The add functionality will work only when you use the ItemsSource property ( working with  a collection) .
This is by design and I believe you will observe the same behavior with any DataForm e.g. the one form Microsoft.

In other works , when using the current item only and not the ItemsSource property , it is not possible to have "Add new " functionality .

Sincerely ,
Pavel Pavlov
the Telerik team
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 Public Issue Tracking system and vote to affect the priority of the items
0
Matt Leeds
Top achievements
Rank 1
answered on 06 May 2011, 07:51 PM
I am having a similar problem.  I am programmatically setting a Collection as the itemsource, but the "add" button is disabled.

((DetailDataContext)DataContext).CommentsDataContext(e.Result.Info);
commentsDataForm.ItemsSource = ((DetailDataContext)DataContext).Comments;
commentsDataForm.UpdateLayout();
0
tomcrusader
Top achievements
Rank 2
answered on 22 Jun 2013, 10:41 AM

I've been stuck on this for weeks and finally, with the help of this post, got it working.

I'm using a GridView with a DomainDataSource and DataForm as in the CRM demo.

OnNavigatedTo I set a "StartAdding" variable to tell the page to try add a new item when it's done.
Simply hooking on to various Loaded events didn't work.

What I did was properly wait for everything to be loaded and then began my editing.

private void DataLoaded(object sender, EventArgs e)
{
    #region ADD ON DATA LOADED
    // Check for "add mode"
    if (!StartAdding) return;
    // Start background worker
    var bw = new BackgroundWorker();
    bw.DoWork += (o, args) =>
    {
        // Wait for gridview to have items
        while (timeRadGridView.Items.CurrentPosition == -1 || timeRadGridView.Items.ItemCount != timeRadGridView.Items.TotalItemCount)
        { }
        // Dispatch BeginAdd method by AddNewItem
        Dispatcher.BeginInvoke(AddNewItem);
        StartAdding = false;
    };
    bw.RunWorkerAsync();
    #endregion
}
 
private void buttonAdd_Click(object sender, RoutedEventArgs e)
{
    // Fallback redirect to self
    if(dataformTime.CanAddItems == false && Parent is Grid)
        App.Navigate((Parent as Grid).Parent as Page, "Time/TimeList?mode=add");
 
    dataformTime.AddNewItem();
    CurrentItem = timeDomainDataSource.DataView.CurrentAddItem as TimeLog;
    dataformTime.CurrentItem = CurrentItem;
    dataformTime.BeginEdit();
}
 
private void BeginAdd()
{
    #region BEGIN ADD
 
    // Disable gridview
    timeRadGridView.IsEnabled = false;
 
    var item = dataformTime.CurrentItem as TimeLog;
    if (item == null)
        App.ShowError("Error adding timelog (BeginAdd)", "Form current item is undefined");
    if (App.CurrentUser.AccountCompany.CompanyId == -1)
        App.ShowError("Error adding timelog (BeginAdd)", "Couldn't find your company");
    else
    {
        item.Created = DateTime.Now;
        item.PersonId = App.CurrentUser.PersonId;
        item.StartDate = DateTime.Now;
        item.TimeLogTypeId = 0;
        item.Disabled = false;
        item.CompanyId = App.CurrentUser.AccountCompany.CompanyId;
        CurrentItem = dataformTime.CurrentItem as TimeLog;
    }
 
    #endregion
}
Tags
DataForm
Asked by
Francois Vanderseypen
Top achievements
Rank 2
Answers by
Pavel Pavlov
Telerik team
Marco Teodoro
Top achievements
Rank 1
Matt Leeds
Top achievements
Rank 1
tomcrusader
Top achievements
Rank 2
Share this question
or