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

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 30, 20262026-05-30T17:27:29+00:00 2026-05-30T17:27:29+00:00

This is my class: [Table] public class ListData : INotifyPropertyChanged, INotifyPropertyChanging { private int

  • 0

This is my class:

 [Table]
public class ListData : INotifyPropertyChanged, INotifyPropertyChanging
{
    private int _id;
    [Column(IsPrimaryKey = true, IsDbGenerated = true, DbType = "INT NOT NULL Identity", CanBeNull = false, AutoSync = AutoSync.OnInsert)]
    public int Id
    {
        get
        {
            return _id;
        }
        set
        {
            if (_id != value)
            {
                OnPropertyChanging("Id");
                _id = value;
                OnPropertyChanged("Id");
            }
        }
    }

    private string _name;
    [Column()]
    public string Name
    {
        get
        { return _name; }
        set
        {
            if (_name != value)
            {
                OnPropertyChanging("Name");
                _name = value;
                OnPropertyChanged("Name");
            }
        }
    }
    private string _url;
    [Column()]
    public string Url
    {
        get
        {
            return _url;
        }
        set
        {
            if (_url != value)
            {
                OnPropertyChanging("Url");
                _url = value;
                OnPropertyChanged("Url");
            }
        }
    }

    public event PropertyChangingEventHandler PropertyChanging;
    public event PropertyChangedEventHandler PropertyChanged;

    private void OnPropertyChanged(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }
    private void OnPropertyChanging(string propertyName)
    {
        if (PropertyChanging != null)
        {
            PropertyChanging(this, new PropertyChangingEventArgs(propertyName));
        }
    }
}

public class ListDataContext : DataContext
{
    public static string DBConnectionString = "Data Source=isostore:/ListDataDB.sdf";
    public ListDataContext(string sConnectionString)
        : base(sConnectionString)
    { }
    public Table<ListData> Datas;
}

this is part of my xaml (listbox):

<ListBox x:Name="listData" Grid.Row="1">
            <ListBox.ItemTemplate>
                <DataTemplate>
                    <StackPanel  Orientation="Horizontal" VerticalAlignment="Center">
                        <TextBlock Text="{Binding Path=Name}" 
                                                   Style="{StaticResource PhoneTextTitle2Style}"
                                                   x:Name="txbName"
                                                   Tap="txbName_Tap">
                        </TextBlock>

                        <Button Tag="{Binding BindsDirectlyToSource=True}" 
                                            Click="Button_Click"  
                                            Content="X" 
                                            BorderBrush="Red" 
                                            Background="Red" 
                                            Foreground="{StaticResource PhoneBackgroundBrush}" 
                                            VerticalAlignment="Top" BorderThickness="0" Width="70" Height="70">
                        </Button>
                    </StackPanel>
                </DataTemplate>
            </ListBox.ItemTemplate>
        </ListBox>

here is my methods for loading data:

public void LoadData()
    {
        this.listData.ItemsSource = GetData();
    }

    public ObservableCollection<ListData> GetData()
    {
        List<ListData> listDatas = new List<ListData>();
        using (var db = new ListDataContext(ConnectionString))
        {
            var query = from e in db.Datas
                        select e;
            listDatas = query.ToList();
        }

        return new ObservableCollection<ListData>(listDatas);
    }

and this is how I delete them:

private void Button_Click(object sender, RoutedEventArgs e)
        {
            try
            {
                var data = (ListData)((Button)sender).Tag;
                using (var db = new ListDataContext(ConnectionString))
                {
                    var entities = from i in db.Datas
                                 where i.Name == data.Name
                                 select i;
                    var entity = entities.FirstOrDefault();
                    db.Datas.DeleteOnSubmit(entity);
                    db.SubmitChanges();
                }
            }
            catch (Exception ex)
            {
                MessageBox.Show(ex.Message);
            }
        }

What´s the problem? Why isn’t my ListBox refreshing after deleting? Is there some problem with ObservableCollection?

  • 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-30T17:27:30+00:00Added an answer on May 30, 2026 at 5:27 pm

    You are removing it from the database, but I don’t see where you call GetData() again, or remove it from the ObservableCollection. Try calling GetData after you delete, or at least manually remove the selected item from the collection.

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

Sidebar

Related Questions

@Entity @Table public class Book { @Id @GeneratedValue @Column private Long bookId; @Column private
Say I have this class: @Entity @Table(name=PICTURE) public class Picture{ private String category1, category2;
This is my Circle class import java.awt.*; public class Circle { private int diameter,
I have this class called Table: class Table { public string Name { get
Why is this thing not working? [Database(Name=Relationships_Test)] [Table(Name = Order)] public class Order {
Given this class public partial class Default : Page { private IRepository repo; ...
template <typename T> class Table { public: Table(); Table(int m, int n); Table(int m,
class table{ name *p; int i; public: table(int j=15){p=new name[i=j]} //constructor ~table(){delete[]p;} } void
I have this class: public abstract class Directory { protected int id; protected File
I have this class and table: public class Foo { public Guid Id {get;set;}

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.