BeginEdit, AddNew, Mode

6 posts, 0 answers
  1. Francois Vanderseypen
    Francois Vanderseypen avatar
    46 posts
    Member since:
    Oct 2009

    Posted 30 Mar 2011 Link to this post

    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.
  2. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 30 Mar 2011 Link to this post

    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
  3. DevCraft banner
  4. Marco Teodoro
    Marco Teodoro avatar
    53 posts
    Member since:
    Apr 2010

    Posted 26 Apr 2011 Link to this post

    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.

  5. Pavel Pavlov
    Admin
    Pavel Pavlov avatar
    2039 posts

    Posted 29 Apr 2011 Link to this post

    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
  6. Matt Leeds
    Matt Leeds avatar
    12 posts
    Member since:
    Apr 2010

    Posted 06 May 2011 Link to this post

    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();
  7. tomcrusader
    tomcrusader avatar
    14 posts
    Member since:
    Jul 2009

    Posted 22 Jun 2013 Link to this post

    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
    }
Back to Top
DevCraft banner