Click here to Skip to main content
15,850,103 members
Home / Discussions / C#
   

C#

 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 3:29
mveOriginalGriff12-Oct-23 3:29 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
jschell12-Oct-23 6:17
jschell12-Oct-23 6:17 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 9:36
mveGerry Schmitz12-Oct-23 9:36 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 10:07
mveOriginalGriff12-Oct-23 10:07 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 10:28
mveGerry Schmitz12-Oct-23 10:28 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 11:20
mveOriginalGriff12-Oct-23 11:20 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
jschell13-Oct-23 8:09
jschell13-Oct-23 8:09 
QuestionItemObservableCollection Pin
rex648-Oct-23 8:34
rex648-Oct-23 8:34 
I have an ItemObservableCollection called _MyChildren with a collection of clsChild. I am trying to get nonfictions when a clsChild.name string is changed.

Error I am getting on MyChildren.ItemPropertyChanged:
Severity	Code	Description	Project	File	Line	Suppression State
Error	CS1661	Cannot convert anonymous method to type 'EventHandler<ItemPropertyChangedEventArgs<clsChild>>' because the parameter types do not match the delegate parameter types	C-Sharp-Tests	C:\Users\Jeff\Documents\GitHub\C-Sharp-Tests\C-Sharp-Tests\C-Sharp-Tests\clsParent.cs	21	Active


clsParent:
using Countdown;
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_Sharp_Tests
{
    internal class clsParent : INotifyPropertyChanged
    {
        public event PropertyChangedEventHandler PropertyChanged;

        private ItemObservableCollection<clsChild> _MyChildren;

        public clsParent()
        {
            _MyChildren = new ItemObservableCollection<clsChild>();
            this._MyChildren.ItemPropertyChanged += delegate (object sender, PropertyChangedEventArgs e)
            {
                if (string.Equals("IsChanged", e.PropertyName, StringComparison.Ordinal))
                {
                    this.RaisePropertyChanged("IsChanged");
                }
            };
        }
    }
}


clsChild:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace C_Sharp_Tests
{
    internal class clsChild : INotifyPropertyChanged
    {
        

        public event PropertyChangedEventHandler PropertyChanged;

        public string name { get; set; }


    }
}


ItemObservableCollection:
using System;
using System.Collections.Generic;
using System.Collections.ObjectModel;
using System.ComponentModel;
using System.Linq;
using System.Text;
using System.Threading.Tasks;

namespace Countdown
{
    /// <summary>
    /// You can use it like this:
    ///     var orders = new ItemObservableCollection<OrderViewModel>();
    ///     orders.CollectionChanged   += OnOrdersChanged;
    ///     orders.ItemPropertyChanged += OnOrderChanged;
    /// </summary>
    /// <typeparam name="T">The type</typeparam>
    public sealed class ItemObservableCollection<T> : ObservableCollection<T>
        where T : INotifyPropertyChanged
    {
        public event EventHandler<ItemPropertyChangedEventArgs<T>> ItemPropertyChanged;

        protected override void InsertItem(int index, T item)
        {
            base.InsertItem(index, item);
            item.PropertyChanged += item_PropertyChanged;
        }

        protected override void RemoveItem(int index)
        {
            var item = this[index];
            base.RemoveItem(index);
            item.PropertyChanged -= item_PropertyChanged;
        }

        protected override void ClearItems()
        {
            foreach (var item in this)
            {
                item.PropertyChanged -= item_PropertyChanged;
            }

            base.ClearItems();
        }

        protected override void SetItem(int index, T item)
        {
            var oldItem = this[index];
            oldItem.PropertyChanged -= item_PropertyChanged;
            base.SetItem(index, item);
            item.PropertyChanged += item_PropertyChanged;
        }

        private void item_PropertyChanged(object sender, PropertyChangedEventArgs e)
        {
            OnItemPropertyChanged((T)sender, e.PropertyName);
        }

        private void OnItemPropertyChanged(T item, string propertyName)
        {
            var handler = this.ItemPropertyChanged;

            if (handler != null)
            {
                handler(this, new ItemPropertyChangedEventArgs<T>(item, propertyName));
            }
        }
    }

    public sealed class ItemPropertyChangedEventArgs<T> : EventArgs
    {
        private readonly T _item;
        private readonly string _propertyName;

        public ItemPropertyChangedEventArgs(T item, string propertyName)
        {
            _item = item;
            _propertyName = propertyName;
        }

        public T Item
        {
            get { return _item; }
        }

        public string PropertyName
        {
            get { return _propertyName; }
        }
    }
}

AnswerRe: ItemObservableCollection Pin
Gerry Schmitz8-Oct-23 8:55
mveGerry Schmitz8-Oct-23 8:55 
QuestionHow do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work4-Oct-23 12:32
Rod at work4-Oct-23 12:32 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan4-Oct-23 21:55
mveRichard MacCutchan4-Oct-23 21:55 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 3:38
Rod at work5-Oct-23 3:38 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 3:43
mveRichard MacCutchan5-Oct-23 3:43 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 4:24
Rod at work5-Oct-23 4:24 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 4:54
Rod at work5-Oct-23 4:54 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 5:18
mveRichard MacCutchan5-Oct-23 5:18 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell5-Oct-23 6:48
jschell5-Oct-23 6:48 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 11:33
Rod at work5-Oct-23 11:33 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell6-Oct-23 8:10
jschell6-Oct-23 8:10 
QuestionBeginner: Return properties from another Class Pin
Member 159530274-Oct-23 0:58
Member 159530274-Oct-23 0:58 
AnswerRe: Beginner: Return properties from another Class Pin
Gerry Schmitz4-Oct-23 5:32
mveGerry Schmitz4-Oct-23 5:32 
AnswerRe: Beginner: Return properties from another Class Pin
Dave Kreskowiak4-Oct-23 6:36
mveDave Kreskowiak4-Oct-23 6:36 
QuestionUsing await/async Correctly Pin
Kevin Marois25-Sep-23 13:30
professionalKevin Marois25-Sep-23 13:30 
AnswerRe: Using await/async Correctly Pin
Gerry Schmitz25-Sep-23 17:13
mveGerry Schmitz25-Sep-23 17:13 
GeneralRe: Using await/async Correctly Pin
Kevin Marois25-Sep-23 17:49
professionalKevin Marois25-Sep-23 17:49 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.