473,385 Members | 2,013 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,385 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
0 1867

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...
1
by: Mike | last post by:
Hi, When trying to remove the icon from a ListViewItem (see code below), the icon does not always disappear. Instead, if I use another index (1, 2, etc.) then the correct icon appears. I was...
2
by: Daniel | last post by:
I'm new to .Net and all of its abilities so I hope this makes sense. Basically I'm confused on when is the appropriate time to use web forms controls vs. regular HTML. For example in ASP...
3
by: sherifffruitfly | last post by:
Hi, Here's a skeleton-handler of what I'm trying to do: private void editBbListView_ItemCheck(object sender, System.Windows.Forms.ItemCheckEventArgs e) { string qEnabled = ""; string...
1
by: sklett | last post by:
I wasn't sure how to deal with this, but this is what I cam up with. If possible, I'd like a little feedback if there is a better way to deal with a situation where changes in an event handler...
1
by: dvestal | last post by:
I have a ListView with checkboxes. I want to remove items when the checkboxes are unchecked, but to do so yields an ArgumentOutOfRangeException. Is there an easy way to get around this? A...
4
by: spowel4 | last post by:
My form has a listview populated with the 50 states. When the user checks the checkbox within the listview for a particular state, I need to retrieve which state was checked (i.e. if AZ is checked...
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...
2
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...
0
by: taylorcarr | last post by:
A Canon printer is a smart device known for being advanced, efficient, and reliable. It is designed for home, office, and hybrid workspace use and can also be used for a variety of purposes. However,...
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
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...
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
by: Hystou | last post by:
Most computers default to English, but sometimes we require a different language, especially when relocating. Forgot to request a specific language before your computer shipped? No problem! You can...
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
jinu1996
by: jinu1996 | last post by:
In today's digital age, having a compelling online presence is paramount for businesses aiming to thrive in a competitive landscape. At the heart of this digital strategy lies an intricately woven...

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.