473,396 Members | 1,764 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.

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
"initialising" before showing the form.
....any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.listView.CheckBoxes = true;
this.listView.View = System.Windows.Forms.View.List;
this.listView.Columns.Add("Test");
this.listView.Items.Add(new ListViewItem("one"));
this.listView.Items.Add(new ListViewItem("two"));
this.listView.Items.Add(new ListViewItem("three"));
this.listView.ItemChecked += new
System.Windows.Forms.ItemCheckedEventHandler(this. listView_ItemChecked);
}
private void listView_ItemChecked(object sender,
ItemCheckedEventArgs e)
{
System.Console.WriteLine("ItemChecked evt: {0} {1}" ,
e.Item, e.Item.Checked);
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.Items[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(15)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("before 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 6778
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****@procom-gmbh.comwrote in message
news:a8**********************************@w28g2000 hsf.googlegroups.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
"initialising" before showing the form.
...any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.listView.CheckBoxes = true;
this.listView.View = System.Windows.Forms.View.List;
this.listView.Columns.Add("Test");
this.listView.Items.Add(new ListViewItem("one"));
this.listView.Items.Add(new ListViewItem("two"));
this.listView.Items.Add(new ListViewItem("three"));
this.listView.ItemChecked += new
System.Windows.Forms.ItemCheckedEventHandler(this. listView_ItemChecked);
}
private void listView_ItemChecked(object sender,
ItemCheckedEventArgs e)
{
System.Console.WriteLine("ItemChecked evt: {0} {1}" ,
e.Item, e.Item.Checked);
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.Items[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(15)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("before 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.com>
wrote:
Peter,>If i check items by code BEFORE the form is shown theListview.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 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...@procom-gmbh.comwrote in message

news:a8**********************************@w28g2000 hsf.googlegroups.com...
Hi,
I have a problem withListviewusing checkboxes.
If i check items by code BEFORE the form is shown theListview.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
"initialising" before showing the form.
...any and suggestions or ideas
Thanks!
Sample:
public partial class Form2 : Form
{
public Form2()
{
InitializeComponent();
this.listView.CheckBoxes = true;
this.listView.View = System.Windows.Forms.View.List;
this.listView.Columns.Add("Test");
this.listView.Items.Add(new ListViewItem("one"));
this.listView.Items.Add(new ListViewItem("two"));
this.listView.Items.Add(new ListViewItem("three"));
this.listView.ItemChecked += new
System.Windows.Forms.ItemCheckedEventHandler(this. listView_ItemChecked);
}
private void listView_ItemChecked(object sender,
ItemCheckedEventArgs e)
{
System.Console.WriteLine("ItemChecked evt: {0} {1}" ,
e.Item, e.Item.Checked);
List("during event");
}
public void Test(string text, bool on)
{
List(text);
this.listView.Items[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(15)); }
}
//---------------------------------------------------------------------
using the form in another form (e.g. Buttonclick)
Form2 frm = new Form2();
frm.Test("before 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
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...
0
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...
6
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...
0
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...
0
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
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. ...
3
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
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...
1
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...
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
1
by: nemocccc | last post by:
hello, everyone, I want to develop a software for my android phone for daily needs, any suggestions?
0
by: Hystou | last post by:
There are some requirements for setting up RAID: 1. The motherboard and BIOS support RAID configuration. 2. The motherboard has 2 or more available SATA protocol SSD/HDD slots (including MSATA, M.2...
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
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,...
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...
0
agi2029
by: agi2029 | last post by:
Let's talk about the concept of autonomous AI software engineers and no-code agents. These AIs are designed to manage the entire lifecycle of a software development project—planning, coding, testing,...

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.