how will i know that the checkbox is clicked not an item in a listview control?

I get this ArgumentOutOfRange exception everytime I click the checkbox column in my listview. I'm using the Click event and not the SelectedIndexChanged for some reasons.

heres the event code:

public static int sel_index = -1;

private static string selectedItem = "";

private void lvwCategory_Click(object sender, System.EventArgs e)

{

sel_index = lvwCategory.SelectedIndices[0]; //the error is here, the index 0

selectedItem = lvwCategory.Items[sel_index].SubItems[1].Text;

}


Answer this question

how will i know that the checkbox is clicked not an item in a listview control?

  • IanRob

    I got it:

    if (lvwClientCategory.SelectedIndices.Count > 0)

    {

    sel_index = lvwCategory.SelectedIndices[0]; //the error is here, the index 0

    selectedItem = lvwCategory.Items[sel_index].SubItems[1].Text;

    }



  • how will i know that the checkbox is clicked not an item in a listview control?