Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 8113653
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: June 6, 20262026-06-06T02:53:51+00:00 2026-06-06T02:53:51+00:00

I have been banging my head on and on, i cant seem to work

  • 0

I have been banging my head on and on, i cant seem to work around the problem i am facing.

Scenario : I have a SalesOrder Page, I am trying to use this page to create new sales orders, as well as edit existing ones. SalesOrder Page hosts, with other controls that bind to current sales order, RadGridView and DataForm. Both bind to same Observable Collection in MVVM.

The Problem i am facing is that,

1) DataForm and Grid Binds to the collection all right, but Edit Button bound to DataForm Edit Command is Disabled. Only the New Button is enabled.

2) After adding a new Item to the dataform, Edit button is Enabled, BUT no matter which row i have selected, it ALWAYS edit the first row that was Inserted, and unless i insert a row, i cannot Edit any existing rows. It seems like DataForm isnt really aware of any existing rows in the collection !!!

My Implimentation : I am using MVVM-light and following is related chunks of my code:

**ViewModel**

below qsdcvSOPDoc is QueryableSouceDomainCollectionView (a wrapper of domain data source for mvvm), The Sales Order Entity in Model is called SOPDoc

   public const string qsdcvSOPDocPropertyName = "qsdcvSOPDoc";
   private QueryableDomainServiceCollectionView<SOPDoc> _qsdcvSOPDoc;
   public QueryableDomainServiceCollectionView<SOPDoc> qsdcvSOPDoc
    {
        get
        {
            return _qsdcvSOPDoc;
        }

        set
        {
            if (_qsdcvSOPDoc == value)
            {
                return;
            }

            var oldValue = _qsdcvSOPDoc;
            _qsdcvSOPDoc = value;
            RaisePropertyChanged(qsdcvSOPDocPropertyName, oldValue, value, true);

below ocSalesOrderItemsList is Obserable Collection that is populated by the IEnumerable, Child Entity of SOPDoc, where is SOPDoc.SOPDocDetails

    public const string ocSalesOrderItemsListPropertyName = "ocSalesOrderItemsList";
    private ObservableCollection<SOPDocDetail> _ocSalesOrderItemsList;
    public ObservableCollection<SOPDocDetail> ocSalesOrderItemsList
    {
        get
        {
            return _ocSalesOrderItemsList;
        }

        set
        {
            if (_ocSalesOrderItemsList == value)
            {
                return;
            }

            var oldValue = _ocSalesOrderItemsList;
            _ocSalesOrderItemsList = value;
            RaisePropertyChanged(ocSalesOrderItemsListPropertyName, oldValue, value, true);
        }
    }

when qsdcvSOPDoc is loaded with data, entCurrentOrder entity is populated with the current sales order, different controls in View binds to this.

    public const string entCurrentOrderPropertyName = "entCurrentOrder";
    private SOPDoc _entCurrentOrder; public SOPDoc entCurrentOrder
    {
        get
        {
            return _entCurrentOrder;
        }

        set
        {
            if (_entCurrentOrder == value)
            {
                return;
            }
            _entCurrentOrder = value;
            RaisePropertyChanged(entCurrentOrderPropertyName);
        }
    }

PageMode is set before navigating to this page, this is set to either ‘New’ or ‘Edit’ and it helps as a check to perform load and save commands as well as trigger some events setting the default values.

    public const string PageModePropertyName = "PageMode";
    private string _pageMode;
    public string PageMode
    {
        get
        {
            return _pageMode;
        }

        set
        {
            if (_pageMode == value)
            {
                return;
            }
            _pageMode = value;
            RaisePropertyChanged(PageModePropertyName);
        }
    }

CurrentSalesOrderId is set while navigating to this page.

    public const string CurrentSalesOrderIdPropertyName = "CurrentSalesOrderId";
    private int _currentSalesOrderId;
    public int CurrentSalesOrderId
    {
        get
        {
            return _currentSalesOrderId;
        }

        set
        {
            if (_currentSalesOrderId == value)
            {
                return;
            }

            var oldValue = _currentSalesOrderId;
            _currentSalesOrderId = value;
            RaisePropertyChanged(CurrentSalesOrderIdPropertyName, oldValue, value, true);
        }
    }

Constructor of ViewModel

 public SalesOrderViewModel()
    {          
            ctx = new KERPDomainContext();
            var ctxDetail = new KERPDomainContext();

            qry = ctx.GetSalesOrderByIdQuery(CurrentSalesOrderId);
            qsdcvSOPDoc = new QueryableDomainServiceCollectionView<SOPDoc>(ctx, qry);
            qsdcvSOPDoc.Load();
            qsdcvSOPDoc.LoadedData += qsdcvSOPDoc_LoadedData;

            ocSalesOrderItemsList = new ObservableCollection<SOPDocDetail>();
            ocSalesOrderItemsList.CollectionChanged += ocSalesOrderItemsList_CollectionChanged; // This will re-calculate the GrossAmount

           //Commands Binding
            SaveSalesOrder = new RelayCommand(SaveSalesOrderExecute, SaveSalesOrderCanExecute);


        }
    }


 void qsdcvSOPDoc_LoadedData(object sender, LoadedDataEventArgs e)
    {

        entCurrentOrder = (SOPDoc)e.Entities.FirstOrDefault();

        if (PageMode == Enums.SODModes.New.ToString() && CurrentSalesOrderId <= 0)
        { // this is a new Sales Order

            if (entCurrentOrder != null)
                ocSalesOrderItemsList.AddRange((entCurrentOrder.SOPDocDetails.Where(i => i.IsActive == true))); // Adds all active items to the collection list

           // setting some values, the property decleration i omitted here for brevity 
           GrossAmount = 0;
            Carriage = 0;
            Discount = 0;

        }


        if (PageMode == Enums.SODModes.Edit.ToString() && CurrentSalesOrderId > 0)
        {
            if (entCurrentOrder != null)
            {
                ocSalesOrderItemsList.AddRange(entCurrentOrder.SOPDocDetails);

                GrossAmount = entCurrentOrder.SOPDocDetails.Sum(i => i.NetAmount);
                Carriage = entCurrentOrder.Carriage;
                Discount = entCurrentOrder.Discount;
            }
        }
    }

View

The View has a RadGridView control and a dataform control both bound to the same ItemSource and CurrentItem:

  <telerik:RadGridView ItemsSource="{Binding ocSalesOrderItemsList}"  Grid.Row="1"                            
                         AutoExpandGroups="True" AutoGenerateColumns="False" ColumnWidth="*" CurrentItem="{Binding entSOPDocDetail}" IsSynchronizedWithCurrentItem="True" IsReadOnly="False">

            <telerik:RadGridView.Columns>
                <telerik:GridViewDataColumn Header="Product Code" DataMemberBinding="{Binding ProductCode}" Width="1.5*"/>
                <telerik:GridViewDataColumn Header="Description" DataMemberBinding="{Binding Description}" Width="5*"/>
                <telerik:GridViewDataColumn Header="Qty" DataMemberBinding="{Binding Qty}" Width="*"/>
                <telerik:GridViewDataColumn Header="UnitType" DataMemberBinding="{Binding UnitType}"/>
                <telerik:GridViewDataColumn Header="Unit Price" DataMemberBinding="{Binding UnitPrice}" DataFormatString="{}{0:0,0.00}"/>
                <telerik:GridViewDataColumn Header="Line Total" DataMemberBinding="{Binding NetAmount}" DataFormatString="{}{0:0,0.00}"/>
                <telerik:GridViewColumn Width="90">
                    <telerik:GridViewColumn.CellTemplate>
                        <DataTemplate>
                            <telerik:RadButton Content="Delete" Command="telerik:RadGridViewCommands.Delete" CommandParameter="{Binding}" />
                        </DataTemplate>
                    </telerik:GridViewColumn.CellTemplate>
                </telerik:GridViewColumn>
            </telerik:RadGridView.Columns>           
    </telerik:RadGridView>

  <telerik:RadDataForm x:Name="dataForm"
                         ItemsSource="{Binding ocSalesOrderItemsList}" 
                         CommandButtonsVisibility="Cancel,Commit" 
                         AutoGenerateFields="False"
                         ValidationSummaryVisibility="Collapsed"
                         EditEnded="RadDataForm_EditEnded"
                         CurrentItemChanged="OnDataFormCurrentItemChanged"
                         LabelPosition="Above"
                         EditTemplate="{StaticResource SOItemsEditTemplate}"
                         NewItemTemplate="{StaticResource SOItemsEditTemplate}" 
                         VerticalContentAlignment="Stretch" HorizontalContentAlignment="Stretch" CurrentItem="{Binding entSOPDocDetail}"/>

Add and Edit buttons are bound to DataForm Commands:

      <telerik:RadButton RenderTransformOrigin="0.5,0.5" Style="{StaticResource smallCommandCircleRadButtons}" Tag="EDIT"
                               Command="telerik:RadDataFormCommands.BeginEdit" CommandTarget="{Binding ElementName=dataForm}" />


      <telerik:RadButton RenderTransformOrigin="0.5,0.5" Style="{StaticResource smallCommandCircleRadButtons}" Margin="0,0,40,0" Tag="ADD ITEM" 
                               Command="telerik:RadDataFormCommands.AddNew" CommandTarget="{Binding ElementName=dataForm}" />

Again – The Problem
The Problem i am facing is that,
1) DataForm and Grid Binds to the collection all right, but Edit Button bound to DataForm Edit Command is Disabled. Only the New Button is enabled.

2) After adding a new Item to the dataform, Edit button is Enabled, BUT no matter which row i have selected, it ALWAYS edit the first row that was Inserted, and unless i insert a row, i cannot Edit any existing rows. It seems like DataForm isnt really aware of any existing rows in the collection !!!

I know there may be principle errors in the approach above, or may be the whole approach is wrong, but that is why i am seeking help!! any suggestions even on a different approach suggestions which involves, CRUD, dataform and Grid with MVVM support, would be very appreciated.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-06-06T02:53:52+00:00Added an answer on June 6, 2026 at 2:53 am

    Well at last i found a way to approach the above by myself and with the help of another question i posted on SO Here.

    what i did actually is, declared a DomainContext ctx and then i loaded it with sales Orders via DomainDataSource1 and another DomainDataSource2 loaded the Order Details. Both of these bound to Grid and Dataform respectively. After all the editing and adding of records, i just called ctx.SaveChanges which saved all the changes to ALL the loaded entities back to Ria.Entity.AcceptChanges() protected method. Thats IT…

    CONCLUSION : Doesnt matter how many DomainDataSources we use to load data into the context, if you want to save them all together, use a SINGLE DomainContext for all of them. Only use saperate DomainContexts if you are going to use partial SubmitChanges :).

    Still need clarification? comment me …….

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I have been banging my head around trying to come up with a query
I am having a problem and have been banging my head aginst a wall...
I have been banging my head trying to figure out what is going wrong.
I have been banging my head for hours trying to figure out why this
I've been banging my head against a wall trying to wrap my head around
I have been banging my head against this problem for days, and searched exhaustively
Hello everyone, I have been banging my head really hard trying to solve this
I've been banging my head all day trying to fix this. I have a
I have been banging my head against the wall trying to figure out this
I'm a newbie with capistrano, and have been banging my head against this problem

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.