CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 4 of 4
  1. #1
    Join Date
    Apr 2002
    Location
    New -york ny
    Posts
    22

    DataGriview issue PLease help!

    I have a datagridview on a windows form and I need to select all the rows in the gridview when the user clicks a check box on the form.
    I put the code in the the Form_Load event handler:
    Code:
    if (ckSelAll.Checked == true)
                 {
                     foreach (DataGridViewRow dgrv in MyGridView.Rows)
                     {
                         dgrv.Selected = true;
                                          }
                 }
    when I load the form and check the checkbox, nothing happens.

    Please help. Thanks.

  2. #2
    Join Date
    Jun 2009
    Posts
    144

    Re: DataGriview issue PLease help!

    create a new button, add this code to the button, check a value and then click on the button then it will work.

    it doesn't work right now because you have it on form load... but when the form loads no one of the values is checked.

  3. #3
    Join Date
    Nov 2007
    Location
    .NET 3.5 / VS2008 Developer
    Posts
    624

    Re: DataGriview issue PLease help!

    I can't remember if there is a property for this, but make sure you can select multiple rows. The datagridview could be set so that only one row can be selected at a time.

  4. #4
    Join Date
    Mar 2005
    Location
    Vienna, Austria
    Posts
    4,538

    Re: DataGriview issue PLease help!

    Code:
    if (ckSelAll.Checked == true)
                 {
                     foreach (DataGridViewRow dgrv in MyGridView.Rows)
                     {
                         dgrv.Selected = true;
                                          }
                 }
    You simple need to put this code into the buttons Click delegate
    Jonny Poet

    To be Alive is depending on the willingsness to help others and also to permit others to help you. So lets be alive. !
    Using Code Tags makes the difference: Code is easier to read, so its easier to help. Do it like this: [CODE] Put Your Code here [/code]
    If anyone felt he has got help, show it in rating the post.
    Also dont forget to set a post which is fully answered to 'resolved'. For more details look to FAQ's about Forum Usage. BTW I'm using Framework 3.5 and you ?
    My latest articles :
    Creating a Dockable Panel-Controlmanager Using C#, Part 1 | Part 2 | Part 3 | Part 4 | Part 5 | Part 6 | Part 7

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  





Click Here to Expand Forum to Full Width

Featured