Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
menu search
person
Welcome To Ask or Share your Answers For Others

Categories

In C# Windows Form Application; Is there an event handler for the ListView control that is fired when items are added to the listview items ?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
216 views
Welcome To Ask or Share your Answers For Others

1 Answer

You dont need to edit other source!

Ok: change from ListView to myListView

Long time ago - but i search for an solution without implements with own ItemAdd-Function! The best way to do it... use the WndProc-Function.

Message: LVM_INSERTITEM

http://msdn.microsoft.com/en-us/library/windows/desktop/bb761107%28v=vs.85%29.aspx

//COMMCTRL.H
#define LVM_FIRST               0x1000           // ListView messages
#define LVM_INSERTITEMA         (LVM_FIRST + 7)  
#define LVM_INSERTITEMW         (LVM_FIRST + 77) 
//edit itemremove (LVM_DELETEITEM)
#define LVM_DELETEITEM          (LVM_FIRST + 8)

C#-implementation

class myListView : ListView {

    protected override void WndProc(ref Message m){
        base.WndProc(ref m);

        switch (m.Msg){
            case 0x1007:    //ListViewItemAdd-A
                System.Diagnostics.Debug.WriteLine("Item added (A)");
                break;
            case 0x104D:    //ListViewItemAdd-W
                System.Diagnostics.Debug.WriteLine("Item added (W)");
                break;
            //edit for itemremove
            case 0x1008:
                System.Diagnostics.Debug.WriteLine("Item removed");
                break;
            case 0x1009:
                System.Diagnostics.Debug.WriteLine("Item removed (All)");
                break;
            default:
                break;
        }
    }
}

Now you can fire your own ItemAddedEvent. I hope that helps other people, who have the same issue.

gegards raiserle

(edit: please vote ;) )


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
thumb_up_alt 0 like thumb_down_alt 0 dislike
Welcome to ShenZhenJia Knowledge Sharing Community for programmer and developer-Open, Learning and Share
...