Results 1 to 7 of 7

Thread: Programmatically Deselect Datagrid

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    Programmatically Deselect Datagrid

    I'm looking for a way to clear datagrid selections programmatically. For instance, if there are highlighted rows in a datagrid I want them to be cleared out (deselected, not highlighted) when the user presses a button thus forcing the user to make new selections. Any help is appreciated.
    A cynic knows the price of everything but the value of nothing.

  2. #2
    Fanatic Member pvbangera's Avatar
    Join Date
    Sep 2001
    Location
    Mumbai, India
    Posts
    961
    i think like listbox, setting row of the grid to -1 may solve the prob. not checked this stuff yet.

    or

    set the focus rectangle of the grid to none or light.


    hope it helps...
    Microsoft Techie

  3. #3

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279
    That doesn't seem to work.
    A cynic knows the price of everything but the value of nothing.

  4. #4
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This unselect specific row .
    VB Code:
    1. me.DataGrid1.UnSelect(row index)

  5. #5
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    This works better .
    VB Code:
    1. Me.DataGrid1.Update()

  6. #6

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279
    Thanks Pirate. Update didn't do anything but the Unselect method did. I have no idea how I missed that. Couldn't see the trees for the forest, I guess. I've got a loop going now:

    Dim x As Int32
    For x = 0 To DataGrid1.VisibleRowCount - 1
    DataGrid1.UnSelect(x)
    Next

    however, just for grins, how do I do this with a For Each Loop?
    A cynic knows the price of everything but the value of nothing.

  7. #7
    Sleep mode
    Join Date
    Aug 2002
    Location
    RUH
    Posts
    8,083
    Update worked for me , though you can try this which repaint the grid .
    VB Code:
    1. Me.DataGrid1.Refresh()
    For the foreach loop , no clue .

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