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 6121349
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 23, 20262026-05-23T15:46:26+00:00 2026-05-23T15:46:26+00:00

I am trying to make a simple Silverlight application that will be hosted on

  • 0

I am trying to make a simple Silverlight application that will be hosted on a SharePoint site.
I am reading the information from the list “testlist” and I am trying to use a dataform control to edit, add and delete data from the list. I am able to delete just fine. When I try to add it adds a new entry with the data from the item previously viewed and I am unable to edit current Items whatsoever. Here is my code:

namespace SP2010
{
public partial class MainPage : UserControl
{
    ClientContext context;
    List customerList;
    ListItemCollection allCustomers;
    public MainPage()
    {
        this.Loaded += new RoutedEventHandler(MainPage_Loaded);
        InitializeComponent();
    }

    void MainPage_Loaded(object sender, RoutedEventArgs e)
    {
        this.DataContext = this;
        context = new ClientContext(ApplicationContext.Current.Url);
        customerList = context.Web.Lists.GetByTitle("testlist");
        context.Load(customerList);
        CamlQuery camlQuery = new CamlQuery();
        camlQuery.ViewXml =@"<View><Query></Query><RowLimit>1000</RowLimit></View>";
        allCustomers = customerList.GetItems(camlQuery);
        context.Load(allCustomers);
        context.ExecuteQueryAsync(new ClientRequestSucceededEventHandler(OnRequestSucceeded), new ClientRequestFailedEventHandler(OnRequestFailed));
    }
    private void OnRequestSucceeded(Object sender, ClientRequestSucceededEventArgs args)
    {
        Dispatcher.BeginInvoke(DisplayListData);
    }
    private void OnRequestFailed(Object sender, ClientRequestFailedEventArgs args)
    {
        MessageBox.Show(args.ErrorDetails + "   " + args.Message);
    }
    public ObservableCollection<SPCustomers> Printers
    {
        get
        {
            if (printers == null)
            {
                printers = new ObservableCollection<SPCustomers>();
                foreach (ListItem item in allCustomers)
                {
                    printers.Add(new SPCustomers
                    {
                        IPAddress = item["Title"].ToString(),
                        Make = item["make"].ToString(),
                        Model = item["model"].ToString(),
                        xCord = item["x"].ToString(),
                        yCord = item["y"].ToString(),
                        id = Convert.ToInt32(item["ID"].ToString())
                    });
                }
            }
            return (printers);
        }
    }
    private ObservableCollection<SPCustomers> printers;
    private void DisplayListData()
    {
        dataForm1.DataContext = Printers;
    }
    private void dataForm1_EditEnded(object sender, DataFormEditEndedEventArgs e)
    {
        if (e.EditAction == DataFormEditAction.Commit)
        {
            if (dataForm1.IsItemChanged)
            {
                customerList = context.Web.Lists.GetByTitle("testlist");
                SPCustomers printer = dataForm1.CurrentItem as SPCustomers;
                ListItem items = customerList.GetItemById(printer.id);
                items["Title"] = printer.IPAddress;
                items["make"] = printer.Make;
                items["model"] = printer.Model;
                items["x"] = printer.xCord;
                items["y"] = printer.yCord;

                items.Update();

                context.ExecuteQueryAsync(OnRequestSucceeded, OnRequestFailed);
            }
        }
    }

    private void dataForm1_AddingNewItem(object sender, DataFormAddingNewItemEventArgs e)
    {
        customerList = context.Web.Lists.GetByTitle("testlist");
        SPCustomers printe = dataForm1.CurrentItem as SPCustomers;
        ListItemCreationInformation itemcreationinfo = new ListItemCreationInformation();
        ListItem items = customerList.AddItem(itemcreationinfo);
        items["Title"] = printe.IPAddress;
        items["make"] = printe.Make;
        items["model"] = printe.Model;
        items["x"] = printe.xCord;
        items["y"] = printe.yCord;

        items.Update();

        context.ExecuteQueryAsync(OnRequestSucceeded, OnRequestFailed);
    }

    private void dataForm1_DeletingItem(object sender, System.ComponentModel.CancelEventArgs e)
    {
        SPCustomers printer = dataForm1.CurrentItem as SPCustomers;
        ListItem oListItem = customerList.GetItemById(printer.id);
        oListItem.DeleteObject();
        context.ExecuteQueryAsync(OnRequestSucceeded, OnRequestFailed);
    }
}
}

and my dataform:

 <df:DataForm ItemsSource="{Binding}"  Height="276" HorizontalAlignment="Left" Margin="12,12,0,0" Name="dataForm1" VerticalAlignment="Top" Width="376" EditEnded="dataForm1_EditEnded" AddingNewItem="dataForm1_AddingNewItem" DeletingItem="dataForm1_DeletingItem" CommandButtonsVisibility="All"  />

Thanks for the help.

update: changed to this will answer in like 7 hours when it lets me

  • 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-05-23T15:46:27+00:00Added an answer on May 23, 2026 at 3:46 pm

    never mind I figured it out I changed my editended to this and deleted my addingNewitem method entirely. Now I just have to hide the ID field and it will be working perfectly

     private void dataForm1_EditEnded(object sender, DataFormEditEndedEventArgs e)
        {
            if (e.EditAction == DataFormEditAction.Commit)
            {
                customerList = context.Web.Lists.GetByTitle("testlist");
                SPCustomers printer = dataForm1.CurrentItem as SPCustomers;
                ListItem items;
                if (printer.id != 0)
                {
                    items = customerList.GetItemById(printer.id);
                }
                else
                {
                    ListItemCreationInformation itemcreationinfo = new ListItemCreationInformation();
                    items = customerList.AddItem(itemcreationinfo);
                }
                    items["Title"] = printer.IPAddress;
                    items["make"] = printer.Make;
                    items["model"] = printer.Model;
                    items["x"] = printer.xCord;
                    items["y"] = printer.yCord;
                    items.Update();
    
                    context.ExecuteQueryAsync(OnRequestSucceeded, OnRequestFailed);                
            }
        }
    
    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

I am trying to make simple regex that will check if a line is
I'm trying to make a simple JQuery button from a div which will change
I'm trying to make a simple application that loads and runs some classes during
I'm trying to make a simple C# web server that, at this stage, you
I'm trying to make a simple php script to find all src attributes from
I'm trying to make simple use of the NSNotification center inside my iPhone application,
Trying to make simple jQuery function to create a scrollToTop button that fades in
I am trying to make simple app that allows one to compare image to
I'm trying to make a simple picture thumbnail application. I've searched the web and
I'm trying to make simple animation that would repeat several times (or infinitely). It

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.