Using VS 2005 C#
I have a listview with CheckBoxes = true.
I want to be able to extract the current index when the CheckBox = true
Can anyone show me how and where to code this- thanks
Using VS 2005 C#
I have a listview with CheckBoxes = true.
I want to be able to extract the current index when the CheckBox = true
Can anyone show me how and where to code this- thanks
Listview Items Checked
Raja-India
Not sure what exactly you need but here is how I would do that.
ListView.CheckedListViewItemCollection checkedItems = listView2.CheckedItems;
foreach (ListViewItem item in checkedItems)
{
..... Type what you need to do with the checked items.
}
This will go through the listbox and let you do something to each one that is check one at a time.
scotts_43035
Your best bets are to use either the ItemChecked event which is triggered when an event is checked (but not unchecked) or the ItemCheck event which is triggered when an item's checkbox has changed state (either becoming checked or unchecked).
Usage of either is as simple as setting up the handlers:
listView1.ItemChecked += new ItemCheckedEventHandler(listView1_ItemChecked);
listView1.ItemCheck += new ItemCheckEventHandler(listView1_ItemCheck);
and then the handling functions:
void listView1_ItemCheck(object sender, ItemCheckEventArgs e)
{
if (e.NewValue == CheckState.Checked)
{
//Do work on item
listView1.Items[e.Index].Text = "Was just checked.";
}
}
void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
{
//Do work on item
e.Item.Text = "Was just checked.";
}
Is this more of what you are looking for
arexey
XWreckage
Thanks that answers part -
I want 'do something' when the box is checked.
The user may check line 3 - then I do something.
The user then checks line 5 - then I do something else.