473,729 Members | 2,309 Online
Bytes | Software Development & Data Engineering Community
+ Post

Home Posts Topics Members FAQ

confused listview.items during itemChecked Event

Hi,

I have a problem with Listview using checkboxes.
If i check items by code BEFORE the form is shown the Listview.Items
are confused during the ItemChecked Event !!!
After showing the form every thing works fine: checking items by code
as well as checking with mouse:
Using the CheckdItems Property is confused too.
I load Settings from XML into different Listboxes, depending on
check-
States differnt data will load from database, so i will doing this
"initialisi ng" before showing the form.
....any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeCompo nent();
this.listView.C heckBoxes = true;
this.listView.V iew = System.Windows. Forms.View.List ;
this.listView.C olumns.Add("Tes t");
this.listView.I tems.Add(new ListViewItem("o ne"));
this.listView.I tems.Add(new ListViewItem("t wo"));
this.listView.I tems.Add(new ListViewItem("t hree"));
this.listView.I temChecked += new
System.Windows. Forms.ItemCheck edEventHandler( this.listView_I temChecked);
}
private void listView_ItemCh ecked(object sender,
ItemCheckedEven tArgs e)
{
System.Console. WriteLine("Item Checked evt: {0} {1}" ,
e.Item, e.Item.Checked) ;
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.I tems[1].Checked = on;
}
private void List(string text)
{
System.Console. WriteLine("{3}: {0}, {1}, {2}",
listView.Items[0].Text,
listView.Items[1].Text,
listView.Items[2].Text,
text.PadRight(1 5)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("befor e Show", true);
frm.Show();
frm.Test("after Show", false);
will show:
before Show : one, two, three
ItemChecked evt: ListViewItem: {one} False
during event : one, one, one ! ! !
ItemChecked evt: ListViewItem: {two} False
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {two} True
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {three} False
during event : one, two, three
after Show : one, two, three
ItemChecked evt: ListViewItem: {two} False
during event : one, two, three
Dec 5 '07 #1
2 6830
Peter,
>If i check items by code BEFORE the form is shown the Listview.Items
are confused during the ItemChecked Event !!!
Unless your event handler writes changes back to the underlying data source
your ListViewItems should not get confused. If you constructed your ListView
before the form is shown, the events, if any, will be fired when the form
becomes visible. If your event handler does change the underlying data, then
you have to prevent unwanted changes caused by events fired automatically,
as opposed to events fired in response to user's input.

I am quite confused by the code you listed. It calls Console from
Windows.Forms?

Michael

"Peter" <pR****@proco m-gmbh.comwrote in message
news:a8******** *************** ***********@w28 g2000hsf.google groups.com...
Hi,

I have a problem with Listview using checkboxes.
If i check items by code BEFORE the form is shown the Listview.Items
are confused during the ItemChecked Event !!!
After showing the form every thing works fine: checking items by code
as well as checking with mouse:
Using the CheckdItems Property is confused too.
I load Settings from XML into different Listboxes, depending on
check-
States differnt data will load from database, so i will doing this
"initialisi ng" before showing the form.
...any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeCompo nent();
this.listView.C heckBoxes = true;
this.listView.V iew = System.Windows. Forms.View.List ;
this.listView.C olumns.Add("Tes t");
this.listView.I tems.Add(new ListViewItem("o ne"));
this.listView.I tems.Add(new ListViewItem("t wo"));
this.listView.I tems.Add(new ListViewItem("t hree"));
this.listView.I temChecked += new
System.Windows. Forms.ItemCheck edEventHandler( this.listView_I temChecked);
}
private void listView_ItemCh ecked(object sender,
ItemCheckedEven tArgs e)
{
System.Console. WriteLine("Item Checked evt: {0} {1}" ,
e.Item, e.Item.Checked) ;
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.I tems[1].Checked = on;
}
private void List(string text)
{
System.Console. WriteLine("{3}: {0}, {1}, {2}",
listView.Items[0].Text,
listView.Items[1].Text,
listView.Items[2].Text,
text.PadRight(1 5)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("befor e Show", true);
frm.Show();
frm.Test("after Show", false);
will show:
before Show : one, two, three
ItemChecked evt: ListViewItem: {one} False
during event : one, one, one ! ! !
ItemChecked evt: ListViewItem: {two} False
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {two} True
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {three} False
during event : one, two, three
after Show : one, two, three
ItemChecked evt: ListViewItem: {two} False
during event : one, two, three


Dec 5 '07 #2
System.Console. WriteLine is just to print out some messages!

You are right: ..."it should not get confused...."
But - if you look at my example, there is no changing in the
datasource !!
Reading Items during the ItemCheck Event before the listview is shown
(visible) birng out wrong results !

Peter
On 5 Dez., 15:59, "Michael Rubinstein" <mSPAM_REMOVEr@ m(R)ubinstein.c om>
wrote:
Peter,>If i check items by code BEFORE the form is shown theListview.Ite ms
are confused during the ItemChecked Event !!!

Unless your event handler writes changes back to the underlying data source
your ListViewItems should not get confused. If you constructed yourListView
before the form is shown, the events, if any, will be fired when the form
becomes visible. If your event handler does change the underlying data, then
you have to prevent unwanted changes caused by events fired automatically,
as opposed to events fired in response to user's input.

I am quite confused by the code you listed. It calls Console from
Windows.Forms?

Michael

"Peter" <pRu...@proco m-gmbh.comwrote in message

news:a8******** *************** ***********@w28 g2000hsf.google groups.com...
Hi,
I have a problem withListviewusi ng checkboxes.
If i check items by code BEFORE the form is shown theListview.Ite ms
are confused during the ItemChecked Event !!!
After showing the form every thing works fine: checking items by code
as well as checking with mouse:
Using the CheckdItems Property is confused too.
I load Settings from XML into different Listboxes, depending on
check-
States differnt data will load from database, so i will doing this
"initialisi ng" before showing the form.
...any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeCompo nent();
this.listView.C heckBoxes = true;
this.listView.V iew = System.Windows. Forms.View.List ;
this.listView.C olumns.Add("Tes t");
this.listView.I tems.Add(new ListViewItem("o ne"));
this.listView.I tems.Add(new ListViewItem("t wo"));
this.listView.I tems.Add(new ListViewItem("t hree"));
this.listView.I temChecked += new
System.Windows. Forms.ItemCheck edEventHandler( this.listView_I temChecked);
}
private void listView_ItemCh ecked(object sender,
ItemCheckedEven tArgs e)
{
System.Console. WriteLine("Item Checked evt: {0} {1}" ,
e.Item, e.Item.Checked) ;
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.I tems[1].Checked = on;
}
private void List(string text)
{
System.Console. WriteLine("{3}: {0}, {1}, {2}",
listView.Items[0].Text,
listView.Items[1].Text,
listView.Items[2].Text,
text.PadRight(1 5)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("befor e Show", true);
frm.Show();
frm.Test("after Show", false);
will show:
before Show : one, two, three
ItemChecked evt: ListViewItem: {one} False
during event : one, one, one ! ! !
ItemChecked evt: ListViewItem: {two} False
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {two} True
during event : one, two, one ! ! !
ItemChecked evt: ListViewItem: {three} False
during event : one, two, three
after Show : one, two, three
ItemChecked evt: ListViewItem: {two} False
during event : one, two, three- Zitierten Text ausblenden -

- Zitierten Text anzeigen -


Dec 6 '07 #3

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

Similar topics

0
1458
by: Marco Auday | last post by:
I need to associate items in two listviews. I have got the drag-and-drop operation to perform as I wanted. However, I would like the items in the target listview to be highlighted when the mouse hovers over them during the drag-and-drop operation, so that I know for sure which item I selected on the target listview. I have tried a number of approaches without success, including: 1) TargetListview.DragEnter event – tried to...
0
2558
by: Samuel R. Neff | last post by:
I'm having a index problem with ListView SubItems. If I add multiple columns to the listview and then add items with associated subitems, the ListView displays fine. Then if I delete a column via ListView.Columns.RemoveAt() then the ListView still displays fine. However, if I grab a subitem value via listView.Items.SubItems.Text Then I get the Text of the wrong column.
6
3415
by: Nick | last post by:
Hi there, I'm trying to implement drag-drop for my listview control in large icon view mode. Unfortunately the order of the items gets completely messed up upon inserting the item back into the listview, removing the item obviously keeps everything fine but the second I use insert the item is added to the *end* of the listview. Does anyone have any tips on how I can solve this issue?? Call Items.Remove(SourceItem)
0
1052
by: Dred | last post by:
'ello I have a listview with checkboxes displaying several options. When one is checked, all it's mutually exclusive counterparts are removed. The problem is that if I check an Item, and remove one of it's previous siblings in the ItemCheck Event, the item does not display as checked. Once I call refresh() it displays fine. Is there some event that gets called after ItemCheck that I can
0
1421
by: Ryan Liu | last post by:
Hi, CheckedListBox has ItemCheck event, how to imitate ItemChecked event? I was trying to use Click event, but it says this is not intended to be used in my code. Thanks a lot! Ryan Liu
12
3412
by: garyusenet | last post by:
I have had no replies to my previous post so perhaps I didn't write it good enough. Please excuse new thread but i wanted to break from the last thread hopefully this thread will be better. Very simple. I would like to create listviewitem's for display in a listview control. The listview items need to contain properties from Internet Explorer windows i've managed to collect into an arraylist.
3
7646
by: RT | last post by:
Is there any way to make Listview items invisible or otherwise keep them from displaying? Seems like temporarily removing, then restoring later would be a severe runtime hit.
0
1893
by: Peter | last post by:
Hi, I have a problem with Listview using checkboxes. If i check items by code BEFORE the form is shown the Listview.Items are confused during the ItemChecked Event !!! After showing the form every thing works fine: checking items by code as well as checking with mouse: Using the CheckdItems Property is confused too.
1
8360
by: =?Utf-8?B?UmF5IE1pdGNoZWxs?= | last post by:
Hello, In my application I need to periodically remove all current items from a ListView and add a new set into it. The following abbreviated code contains the basic idea: private void FillListViewFromFile(string path) {
0
8917
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, people are often confused as to whether an ONU can Work As a Router. In this blog post, we’ll explore What is ONU, What Is Router, ONU & Router’s main usage, and What is the difference between ONU and Router. Let’s take a closer look ! Part I. Meaning of...
0
9426
Oralloy
by: Oralloy | last post by:
Hello folks, I am unable to find appropriate documentation on the type promotion of bit-fields when using the generalised comparison operator "<=>". The problem is that using the GNU compilers, it seems that the internal comparison operator "<=>" tries to promote arguments from unsigned to signed. This is as boiled down as I can make it. Here is my compilation command: g++-12 -std=c++20 -Wnarrowing bit_field.cpp Here is the code in...
1
9200
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 Update option using the Control Panel or Settings app; it automatically checks for updates and installs any it finds, whether you like it or not. For most users, this new feature is actually very convenient. If you want to control the update process,...
0
9142
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 protocol has its own unique characteristics and advantages, but as a user who is planning to build a smart home system, I am a bit confused by the choice of these technologies. I'm particularly interested in Zigbee because I've heard it does some...
1
6722
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 1 May 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome a new presenter, Adolph Dupré who will be discussing some powerful techniques for using class modules. He will explain when you may want to use classes instead of User Defined Types (UDT). For example, to manage the data in unbound forms. Adolph will...
0
6022
by: conductexam | last post by:
I have .net C# application in which I am extracting data from word file and save it in database particularly. To store word all data as it is I am converting the whole word file firstly in HTML and then checking html paragraph one by one. At the time of converting from word file to html my equations which are in the word document file was convert into image. Globals.ThisAddIn.Application.ActiveDocument.Select();...
0
4795
by: adsilva | last post by:
A Windows Forms form does not have the event Unload, like VB6. What one acts like?
1
3238
by: 6302768590 | last post by:
Hai team i want code for transfer the data from one system to another through IP address by using C# our system has to for every 5mins then we have to update the data what the data is updated we have to send another system
3
2163
bsmnconsultancy
by: bsmnconsultancy | last post by:
In today's digital era, a well-designed website is crucial for businesses looking to succeed. Whether you're a small business owner or a large corporation in Toronto, having a strong online presence can significantly impact your brand's success. BSMN Consultancy, a leader in Website Development in Toronto offers valuable insights into creating effective websites that not only look great but also perform exceptionally well. In this comprehensive...

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.