C# ListView question

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Jason Huang

    C# ListView question

    Hi,

    In my C# Windows Form MyForm, it has a ListView ListView1.
    If I click those ListViewItems in ListView1, it's OK; but if I click empty
    space in ListView1 rather than those ListViewItems, then there will come
    errors.
    How do I fix this problem?
    Thanks for help.


    Jason


  • Dale

    #2
    RE: C# ListView question

    You should provide some more details of which event you're handling, what
    you're doing in that event handler that is throwing exceptions and what those
    exceptions are.

    A quick guess on my part is that you may be handling the Click event and
    then, in your code, trying to do something with SelectedItems. If you
    clicked an empty area of the ListView then SelectedItems would be empty. The
    solution would be to verify that SelectedItems.C ount is not 0 before doing
    anything with SelectedItems in your event handler.

    HTH
    --
    Dale Preston
    MCAD C#
    MCSE, MCDBA


    "Jason Huang" wrote:
    [color=blue]
    > Hi,
    >
    > In my C# Windows Form MyForm, it has a ListView ListView1.
    > If I click those ListViewItems in ListView1, it's OK; but if I click empty
    > space in ListView1 rather than those ListViewItems, then there will come
    > errors.
    > How do I fix this problem?
    > Thanks for help.
    >
    >
    > Jason
    >
    >
    >[/color]

    Comment

    • Ignacio Machin \( .NET/ C# MVP \)

      #3
      Re: C# ListView question

      Hi,

      "Jason Huang" <JasonHuang8888 @hotmail.com> wrote in message
      news:uLuEuwwIGH A.3064@TK2MSFTN GP10.phx.gbl...[color=blue]
      > Hi,
      >
      > In my C# Windows Form MyForm, it has a ListView ListView1.
      > If I click those ListViewItems in ListView1, it's OK; but if I click empty
      > space in ListView1 rather than those ListViewItems, then there will come
      > errors.
      > How do I fix this problem?[/color]


      What error?
      Post the code of the handler or at least the description of the exception


      --
      Ignacio Machin,
      ignacio.machin AT dot.state.fl.us
      Florida Department Of Transportation


      Comment

      • Jason Huang

        #4
        Re: C# ListView question

        ?
        "Jason Huang" <JasonHuang8888 @hotmail.com> ¼¶¼g©ó¶l¥ó·s»D: uLuEuwwIGHA.306 4@TK2MSFTNGP10. phx.gbl...[color=blue]
        > Hi,
        >
        > In my C# Windows Form MyForm, it has a ListView ListView1.
        > If I click those ListViewItems in ListView1, it's OK; but if I click empty
        > space in ListView1 rather than those ListViewItems, then there will come
        > errors.
        > How do I fix this problem?
        > Thanks for help.
        >
        >
        > Jason
        >[/color]


        Comment

        Working...