none
Select Row with CheckBox in ListView RRS feed

  • Question

  • I have a ListView object which have CheckBox enable.  I need to select the entire row if a user activate the checkbox.  I know I can used the listView1_ItemChecked to monitor the check event but how do I select the entire row? I'm trying to eliminate the user from holding the ctrl or shift key to select mutli row.

    Thank you.


    • Edited by zXSwordXz Friday, March 15, 2013 5:04 PM
    Friday, March 15, 2013 5:04 PM

Answers

  • Hi zXSwordXz,

    ListView.FullRowSelect Property indicating whether clicking an item selects all its subitems. Therefore, you can select entire row by set one item to selected.

    private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
    {
        this.listView1.FullRowSelect = e.Item.Checked;
        if (e.Item.Checked)
        {
            e.Item.Selected = true;
        }
    }
    
    private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
    {
        this.listView1.FullRowSelect = e.Item.Checked;
    
    }

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by zXSwordXz Tuesday, March 19, 2013 2:11 PM
    • Unmarked as answer by zXSwordXz Tuesday, March 19, 2013 2:12 PM
    • Marked as answer by zXSwordXz Thursday, May 9, 2013 5:18 PM
    Monday, March 18, 2013 6:22 AM
    Moderator

All replies

  • ListView has a MultiSelect property you can set to false.

    There is also a SelectedItems property and you can check if anything is already selected with : ListView1.SelectedItems.Count > 0


    Bob - www.crowcoder.com

    Friday, March 15, 2013 5:53 PM
  • Hi zXSwordXz,

    ListView.FullRowSelect Property indicating whether clicking an item selects all its subitems. Therefore, you can select entire row by set one item to selected.

    private void listView1_ItemChecked(object sender, ItemCheckedEventArgs e)
    {
        this.listView1.FullRowSelect = e.Item.Checked;
        if (e.Item.Checked)
        {
            e.Item.Selected = true;
        }
    }
    
    private void listView1_ItemSelectionChanged(object sender, ListViewItemSelectionChangedEventArgs e)
    {
        this.listView1.FullRowSelect = e.Item.Checked;
    
    }

    Best Regards,


    Bob Wu
    MSDN Community Support | Feedback to us
    Develop and promote your apps in Windows Store
    Please remember to mark the replies as answers if they help and unmark them if they provide no help.

    • Marked as answer by zXSwordXz Tuesday, March 19, 2013 2:11 PM
    • Unmarked as answer by zXSwordXz Tuesday, March 19, 2013 2:12 PM
    • Marked as answer by zXSwordXz Thursday, May 9, 2013 5:18 PM
    Monday, March 18, 2013 6:22 AM
    Moderator
  • @Bob..Thank you. That work perfectly.  However, I have a follow up question.  Is there a way to disable the selection by click on the actual items in the listview? Therefore, forcing the users to only used the check box?
    • Edited by zXSwordXz Tuesday, March 19, 2013 3:18 PM
    Tuesday, March 19, 2013 2:27 PM