Jump to content

ListView error

- - - - -

  • Please log in to reply
2 replies to this topic

#1
Peacemaker

Peacemaker

    Newbie

  • Members
  • PipPip
  • 11 posts
I used this code:
switch ((sender as ContextMenuStrip).SourceControl.Name)

            {

                case "listViewH":

                    CopyListViewToClipboard(listViewH);

                    break;

                case "listViewData":

                    CopyListViewToClipboard(listViewData);

                    break;

                case "listViewSys":

                    CopyListViewToClipboard(listViewSys);

                    break;

                case "listViewMem":

                    CopyListViewToClipboard(listViewMem);

                    break;

                case "listViewNet":

                    CopyListViewToClipboard(listViewNet);

                    break;

                case "listViewUser":

                    CopyListViewToClipboard(listViewUser);

                    break;

                case "listViewDev":

                    CopyListViewToClipboard(listViewDev);

                    break;

                case "listViewUlt":

                    CopyListViewToClipboard(listViewUlt);

                    break;

            }

or i try this:

CopyListViewToClipboard((ListView)(sender as ContextMenuStrip).SourceControl);

And i am getting "Object reference not set to an instance of an object.".
spammy sig deleted by management

#2
BlackRabbit

BlackRabbit

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 256 posts
  • Location:ten steps forward
You need to copy the whole code, but my money is some of those list are initialized either as objets or have null content and your CopyListViewToClipboard method is not checking for it.

#3
kernelcoder

kernelcoder

    Programming Professional

  • Members
  • PipPipPipPipPip
  • 289 posts
  • Location:Dhaka
  • Programming Language:C, Java, C++, C#, Visual Basic .NET
  • Learning:Objective-C, PHP, Python, Delphi/Object Pascal
I guess the problem is in (ListView)(sender asContextMenuStrip). First you converted a ListView (sender as ContextMenuString) to ContextMenuStrip which should not happen as ListView is NOT a base-class of ContextMenuStrip.

I think the code will work if you omit the (ListView) casting part.




1 user(s) are reading this topic

0 members, 1 guests, 0 anonymous users