C# ListView question

  • Thread starter Thread starter Jason Huang
  • Start date Start date
J

Jason Huang

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
 
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.Count is not 0 before doing
anything with SelectedItems in your event handler.

HTH
 
Hi,

Jason Huang said:
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?


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