Click here to Skip to main content
15,892,674 members
Home / Discussions / C#
   

C#

 
GeneralRe: Cannot run setup project on Windows XP Pin
DPaul199422-Aug-15 11:50
DPaul199422-Aug-15 11:50 
QuestionShockwaveFlashObjects gives 'System.AccessViolationException' Pin
DPaul199421-Aug-15 9:25
DPaul199421-Aug-15 9:25 
AnswerRe: ShockwaveFlashObjects gives 'System.AccessViolationException' Pin
Richard MacCutchan21-Aug-15 21:57
mveRichard MacCutchan21-Aug-15 21:57 
GeneralRe: ShockwaveFlashObjects gives 'System.AccessViolationException' Pin
DPaul199422-Aug-15 0:05
DPaul199422-Aug-15 0:05 
GeneralRe: ShockwaveFlashObjects gives 'System.AccessViolationException' Pin
Richard MacCutchan22-Aug-15 0:18
mveRichard MacCutchan22-Aug-15 0:18 
GeneralRe: ShockwaveFlashObjects gives 'System.AccessViolationException' Pin
DPaul199422-Aug-15 0:21
DPaul199422-Aug-15 0:21 
GeneralRe: ShockwaveFlashObjects gives 'System.AccessViolationException' Pin
DPaul199422-Aug-15 12:13
DPaul199422-Aug-15 12:13 
Questionon the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
BillWoodruff21-Aug-15 6:46
professionalBillWoodruff21-Aug-15 6:46 
By sticking a static CollectionChanged EventHandler in an ObservableCollection<T> ... well, it works. Every new Node created gets its internal Nodes collection hooked-up to the Event.

But, I have, as is so often said in CP Q&A: "a doubt." Is this okay, or am I violating something or other ?

C#
// required
using System.Collections.Generic;
using System.Collections.ObjectModel;

public class Nodes<T> : ObservableCollection<Node<T>>
{
    public Nodes()
    {
        this.CollectionChanged += Nodes_CollectionChanged;
    }

    public static void Nodes_CollectionChanged(object sender, System.Collections.Specialized.NotifyCollectionChangedEventArgs e)
    {
        string txt = (e.NewItems[0] as Node<T>).Text;

        Console.WriteLine("{0} {1} {2} {3}", e.Action.ToString(), txt, e.OldStartingIndex.ToString(), e.NewStartingIndex.ToString());
    }

    public void Add(string text)
    {
        Node<T> newNode = new Node<T>(text);
        base.Add(newNode);
    }

    public void Add(T value, string text)
    {
        Node<T> newNode = new Node<T>(text) {Value = value};
        base.Add(newNode);
    }
}

public class Node<T>
{
    public T Value { set; get; }
    public string Text { set; get; }
    public Nodes<T> Nodes { set; get; }

    public Node(string text = "")
    {
        Text = text;
        Nodes = new Nodes<T>();
    }

    public Node(T value, string text = "")
    {
        Value = value;
        Text = text;
        Nodes = new Nodes<T>();
    }
}

// test : Button Click on a Form
private void TestNotification_Click(object sender, EventArgs e)
{
     Nodes<string> TestNodes = new Nodes<string>();
     TestNodes.Add("root");
     TestNodes[0].Nodes.Add("child 1");
     TestNodes[0].Nodes[0].Add("child1 of child1");
}

/* output of the test
Add root -1 0
Add child 1 -1 0
Add child1 of child1 -1 0*/

«I want to stay as close to the edge as I can without going over. Out on the edge you see all kinds of things you can't see from the center» Kurt Vonnegut.

AnswerRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
Eddy Vluggen21-Aug-15 10:09
professionalEddy Vluggen21-Aug-15 10:09 
GeneralRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
Brisingr Aerowing21-Aug-15 12:16
professionalBrisingr Aerowing21-Aug-15 12:16 
GeneralRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
Eddy Vluggen21-Aug-15 13:00
professionalEddy Vluggen21-Aug-15 13:00 
GeneralRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
BillWoodruff21-Aug-15 14:54
professionalBillWoodruff21-Aug-15 14:54 
GeneralRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
BillWoodruff21-Aug-15 14:23
professionalBillWoodruff21-Aug-15 14:23 
GeneralRe: on the path or out to lunch ? ... hierarchic event notification with ObservableCollection<T> Pin
Eddy Vluggen22-Aug-15 0:00
professionalEddy Vluggen22-Aug-15 0:00 
QuestionC# Textbox disabler Pin
Andrei Ang21-Aug-15 1:05
Andrei Ang21-Aug-15 1:05 
AnswerRe: C# Textbox disabler Pin
OriginalGriff21-Aug-15 1:10
mveOriginalGriff21-Aug-15 1:10 
GeneralRe: C# Textbox disabler Pin
Andrei Ang21-Aug-15 1:43
Andrei Ang21-Aug-15 1:43 
GeneralRe: C# Textbox disabler Pin
OriginalGriff21-Aug-15 1:54
mveOriginalGriff21-Aug-15 1:54 
GeneralRe: C# Textbox disabler Pin
Andrei Ang21-Aug-15 2:04
Andrei Ang21-Aug-15 2:04 
GeneralRe: C# Textbox disabler Pin
OriginalGriff21-Aug-15 2:11
mveOriginalGriff21-Aug-15 2:11 
GeneralRe: C# Textbox disabler Pin
Andrei Ang21-Aug-15 2:21
Andrei Ang21-Aug-15 2:21 
GeneralRe: C# Textbox disabler Pin
OriginalGriff21-Aug-15 2:32
mveOriginalGriff21-Aug-15 2:32 
GeneralRe: C# Textbox disabler Pin
Andrei Ang21-Aug-15 2:45
Andrei Ang21-Aug-15 2:45 
GeneralRe: C# Textbox disabler Pin
Eddy Vluggen21-Aug-15 3:59
professionalEddy Vluggen21-Aug-15 3:59 
GeneralRe: C# Textbox disabler Pin
OriginalGriff21-Aug-15 4:04
mveOriginalGriff21-Aug-15 4:04 

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.