473,323 Members | 1,547 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,323 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 1861

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: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
0
by: ArrayDB | last post by:
The error message I've encountered is; ERROR:root:Error generating model response: exception: access violation writing 0x0000000000005140, which seems to be indicative of an access violation...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: Shællîpôpï 09 | last post by:
If u are using a keypad phone, how do u turn on JavaScript, to access features like WhatsApp, Facebook, Instagram....
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
by: Faith0G | last post by:
I am starting a new it consulting business and it's been a while since I setup a new website. Is wordpress still the best web based software for hosting a 5 page website? The webpages will be...
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 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 former...

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.