Click here to Skip to main content
15,887,214 members
Home / Discussions / C#
   

C#

 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 2:29
mveOriginalGriff12-Oct-23 2:29 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
jschell12-Oct-23 5:17
jschell12-Oct-23 5:17 
AnswerRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 8:36
mveGerry Schmitz12-Oct-23 8:36 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 9:07
mveOriginalGriff12-Oct-23 9:07 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
Gerry Schmitz12-Oct-23 9:28
mveGerry Schmitz12-Oct-23 9:28 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
OriginalGriff12-Oct-23 10:20
mveOriginalGriff12-Oct-23 10:20 
GeneralRe: Creating a JSON File from a CSV file in C# Pin
jschell13-Oct-23 7:09
jschell13-Oct-23 7:09 
QuestionItemObservableCollection Pin
rex648-Oct-23 7:34
rex648-Oct-23 7: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 7:55
mveGerry Schmitz8-Oct-23 7:55 
QuestionHow do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work4-Oct-23 11:32
Rod at work4-Oct-23 11:32 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan4-Oct-23 20:55
mveRichard MacCutchan4-Oct-23 20:55 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 2:38
Rod at work5-Oct-23 2:38 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 2:43
mveRichard MacCutchan5-Oct-23 2:43 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 3:24
Rod at work5-Oct-23 3:24 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 3:54
Rod at work5-Oct-23 3:54 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Richard MacCutchan5-Oct-23 4:18
mveRichard MacCutchan5-Oct-23 4:18 
AnswerRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell5-Oct-23 5:48
jschell5-Oct-23 5:48 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
Rod at work5-Oct-23 10:33
Rod at work5-Oct-23 10:33 
GeneralRe: How do I use Visual Studio user secrets and GitHub secrets, in the same project? Pin
jschell6-Oct-23 7:10
jschell6-Oct-23 7:10 
QuestionBeginner: Return properties from another Class Pin
Member 159530273-Oct-23 23:58
Member 159530273-Oct-23 23:58 
AnswerRe: Beginner: Return properties from another Class Pin
Gerry Schmitz4-Oct-23 4:32
mveGerry Schmitz4-Oct-23 4:32 
AnswerRe: Beginner: Return properties from another Class Pin
Dave Kreskowiak4-Oct-23 5:36
mveDave Kreskowiak4-Oct-23 5:36 
QuestionUsing await/async Correctly Pin
Kevin Marois25-Sep-23 12:30
professionalKevin Marois25-Sep-23 12:30 
AnswerRe: Using await/async Correctly Pin
Gerry Schmitz25-Sep-23 16:13
mveGerry Schmitz25-Sep-23 16:13 
GeneralRe: Using await/async Correctly Pin
Kevin Marois25-Sep-23 16:49
professionalKevin Marois25-Sep-23 16: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.