469,140 Members | 1,368 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 469,140 developers. It's quick & easy.

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 1602

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

1 post views Thread by Mike | last post: by
2 posts views Thread by Daniel | last post: by
4 posts views Thread by spowel4 | last post: by
1 post views Thread by Mortomer39 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.