473,396 Members | 2,139 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,396 software developers and data experts.

System.Windows.Forms.ListView: OnItemCheck method called when displaying the form

Is there any way to know whether the OnItemCheck is being called in response
to a user action (mouse or keyboard) as opposed to the form loading?

I have a class which derives from System.Windows.Forms.ListView. Among
other features, it enables the checkboxes and overrides the OnItemCheck()
method. I have placed this ListView on a form and use form.ShowDialog() to
display it whenever the user presses a certain button.

If the user ticks any of the items in the ListView, and then presses the
button again, the form displays okay, but it calls the OnItemCheck() method
twice for each item that was previously checked (once to uncheck, and again
to check the item).

The problem is, that I keep track of the order in which the user checked the
checkboxes, and when OnItemCheck is called it effectively changes the order
to be the same as the insertion order in the list.

Thanks,
Aaron Queenan.
Nov 15 '05 #1
2 2985
100
Hi Aaron,
ItemCheck event is raised whenever an item changes its check status. It can
be done programmatically or by the user. There is no way to now how the item
has been changed its state.
However the control doesn't fire the event before it is created or if it is
created with Visible property set to false. Which means that you can fill up
and set the check status of the items without any ItemCheck event fired. But
once you show the control you cannot stop the events even if you set Visible
back to *false*.
I see that you have overridden the control. In this case you can add a
property say "bool SuppressItemCheckEvent";
If this flag is set in your OnItemCheck don't call base.OnItemCheck this
will suppress the event.
Now you can set
SuppressItemCheckEvent = true;
change the state of items
SuppressItemCheckEvent = false;

HTH
B\rgds
100

"Aaron Queenan" <aq*********************@contingent.com.au> wrote in message
news:u2**************@TK2MSFTNGP11.phx.gbl...
Is there any way to know whether the OnItemCheck is being called in response to a user action (mouse or keyboard) as opposed to the form loading?

I have a class which derives from System.Windows.Forms.ListView. Among
other features, it enables the checkboxes and overrides the OnItemCheck()
method. I have placed this ListView on a form and use form.ShowDialog() to display it whenever the user presses a certain button.

If the user ticks any of the items in the ListView, and then presses the
button again, the form displays okay, but it calls the OnItemCheck() method twice for each item that was previously checked (once to uncheck, and again to check the item).

The problem is, that I keep track of the order in which the user checked the checkboxes, and when OnItemCheck is called it effectively changes the order to be the same as the insertion order in the list.

Thanks,
Aaron Queenan.

Nov 15 '05 #2
I can get around the problem of the events firing on loading, by using the
following code at the top of OnItemCheck():

if (ice.Index >= this.Items.Count)
return;

However, the method still gets called if I hide then show the form. The
problem is that the ListView unchecks then rechecks each checked item in the
list. That is utterly stupid! The items haven't changed, and there is no
reason for anything to uncheck then recheck them, but perhaps when the form
recreates the underlying control the internal ListView illogic isn't clever
enough to realise that the events should be discarded, and calls
OnItemCheck().

Do you know what events fire before or after showing the form? Is there any
way to watch the events being fired, without handling them all? I am
thinking of setting a flag called "IgnoreBogusListViewEvents" in an event
which occurs first and clearing it afterwards.

Thanks,
Aaron.

"100" <10*@100.com> wrote in message
news:u3**************@TK2MSFTNGP10.phx.gbl...
Hi Aaron,
ItemCheck event is raised whenever an item changes its check status. It can be done programmatically or by the user. There is no way to now how the item has been changed its state.
However the control doesn't fire the event before it is created or if it is created with Visible property set to false. Which means that you can fill up and set the check status of the items without any ItemCheck event fired. But once you show the control you cannot stop the events even if you set Visible back to *false*.
I see that you have overridden the control. In this case you can add a
property say "bool SuppressItemCheckEvent";
If this flag is set in your OnItemCheck don't call base.OnItemCheck this
will suppress the event.
Now you can set
SuppressItemCheckEvent = true;
change the state of items
SuppressItemCheckEvent = false;

HTH
B\rgds
100

"Aaron Queenan" <aq*********************@contingent.com.au> wrote in message news:u2**************@TK2MSFTNGP11.phx.gbl...
Is there any way to know whether the OnItemCheck is being called in

response
to a user action (mouse or keyboard) as opposed to the form loading?

I have a class which derives from System.Windows.Forms.ListView. Among
other features, it enables the checkboxes and overrides the OnItemCheck() method. I have placed this ListView on a form and use form.ShowDialog()

to
display it whenever the user presses a certain button.

If the user ticks any of the items in the ListView, and then presses the
button again, the form displays okay, but it calls the OnItemCheck()

method
twice for each item that was previously checked (once to uncheck, and

again
to check the item).

The problem is, that I keep track of the order in which the user checked

the
checkboxes, and when OnItemCheck is called it effectively changes the

order
to be the same as the insertion order in the list.

Thanks,
Aaron Queenan.


Nov 15 '05 #3

This thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

9
by: Penn Markham | last post by:
Hello all, I am writing a script where I need to use the system() function to call htpasswd. I can do this just fine on the command line...works great (see attached file, test.php). When my...
2
by: Phil Stanton | last post by:
When designing a new form or report, the Default ForeColor is often something like -2147483640 which is the colour of Windows text (possibly black) and the default backColor is -2147483643...
3
by: Travis | last post by:
I am trying to display a query like this in my windows form: SELECT workordernumber, date, firstname, lastname FROM customer_db; I am using a rich text box to display the data but it only...
6
by: Dan | last post by:
I've created a pocketpc app which has a startup form containing a listview. The form creates an object which in turn creates a System.Threading.Timer. It keeps track of the Timer state using a...
2
by: Raed Sawalha | last post by:
i have a windows form(Main) with listview, when click an item in listview i open other window form (Sub) which generate the selected item from parent window in as treeview items when click any item...
7
by: Steve954 | last post by:
I recently installed and started using VS2005 on a Windows XP Pro machine. When creating a new windows forms project I find that I am unable to hide any forms using the me.hide() or me.visible =...
3
by: forest demon | last post by:
for example, let's say I do something like, System.Diagnostics.Process.Start("notepad.exe","sample.txt"); if the user does a SaveAs (in notepad), how can i capture the path that the user...
2
by: feltra | last post by:
Hi, The following is from my friend, who has some technical problem at present in accessing the web... I am writing for him... Kindly request your inputs ASAP, as he has some kind of deadline...
2
by: =?Utf-8?B?TmF0aGFuIFdpZWdtYW4=?= | last post by:
Hi, I am wondering why the .NET Framework is quite different from Win32 API when it comes to displaying system modal message boxes. Consider the four following types of system modal message...
0
by: Charles Arthur | last post by:
How do i turn on java script on a villaon, callus and itel keypad mobile phone
0
by: ryjfgjl | last post by:
In our work, we often receive Excel tables with data in the same format. If we want to analyze these data, it can be difficult to analyze them because the data is spread across multiple Excel files...
0
by: emmanuelkatto | last post by:
Hi All, I am Emmanuel katto from Uganda. I want to ask what challenges you've faced while migrating a website to cloud. Please let me know. Thanks! Emmanuel
0
BarryA
by: BarryA | last post by:
What are the essential steps and strategies outlined in the Data Structures and Algorithms (DSA) roadmap for aspiring data scientists? How can individuals effectively utilize this roadmap to progress...
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
1
by: Sonnysonu | last post by:
This is the data of csv file 1 2 3 1 2 3 1 2 3 1 2 3 2 3 2 3 3 the lengths should be different i have to store the data by column-wise with in the specific length. suppose the i have to...
0
marktang
by: marktang | last post by:
ONU (Optical Network Unit) is one of the key components for providing high-speed Internet services. Its primary function is to act as an endpoint device located at the user's premises. However,...
0
by: Hystou | last post by:
Overview: Windows 11 and 10 have less user interface control over operating system update behaviour than previous versions of Windows. In Windows 11 and 10, there is no way to turn off the Windows...
0
tracyyun
by: tracyyun | last post by:
Dear forum friends, With the development of smart home technology, a variety of wireless communication protocols have appeared on the market, such as Zigbee, Z-Wave, Wi-Fi, Bluetooth, etc. Each...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.