Get GridViewCheckBoxColumn selected on grid

4 posts, 2 answers
  1. Flávio
    Flávio avatar
    16 posts
    Member since:
    Jun 2011

    Posted 08 Sep 2011 Link to this post

    Hi,

       I'd like know how to do get value of rows selected with CheckBox on GridView?
    Example:

    Name               |  Selected
    Steve Jobs        
    Bill Gates                x
    Larry Page
    Mark Zuck               x

    Your select Bill Gates and Mark Zuck.

    I tried with foreach, but isn't get the values selected.

    Thanks attention!

  2. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 09 Sep 2011 Link to this post

    Hello Flavio,

    You can use the following:
    var checkedRows = radGridView1.Rows.Where(r => r.Cells[2].Value != null && r.Cells[2].Value is bool && (bool)r.Cells[2].Value);

    where 2 is the index for the column, or you can use the name of the column directly.

    Hope this helps, if you have any other questions please let me know,

    Best Regards,
    Emanuel Varga

    WinForms MVP
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Flávio
    Flávio avatar
    16 posts
    Member since:
    Jun 2011

    Posted 09 Sep 2011 Link to this post

    Hi Emanuel,

       I tried implent your code in my application, but isn't worked. Occured a error when I set radGridView1.Rows.Where(...), where isn't exist.
    Do you have any tip what can be?

    Image with message error attached!

    Thanks attention!
  5. Answer
    Emanuel Varga
    Emanuel Varga avatar
    1336 posts
    Member since:
    May 2010

    Posted 09 Sep 2011 Link to this post

    Hello

    Just add using System.Linq; to the references if you are using .net 3.5, if not, let me know and i'll reformat the code.

    Best regards,
    Emanuel Varga
Back to Top