Skip to content
  • Categories
  • Recent
  • Tags
  • Popular
  • World
  • Users
  • Groups
Skins
  • Light
  • Cerulean
  • Cosmo
  • Flatly
  • Journal
  • Litera
  • Lumen
  • Lux
  • Materia
  • Minty
  • Morph
  • Pulse
  • Sandstone
  • Simplex
  • Sketchy
  • Spacelab
  • United
  • Yeti
  • Zephyr
  • Dark
  • Cyborg
  • Darkly
  • Quartz
  • Slate
  • Solar
  • Superhero
  • Vapor

  • Default (No Skin)
  • No Skin
Collapse
Code Project
  1. Home
  2. General Programming
  3. C#
  4. how to get the indexes of selected items in DataGrid?

how to get the indexes of selected items in DataGrid?

Scheduled Pinned Locked Moved C#
questiontutorial
2 Posts 2 Posters 0 Views 1 Watching
  • Oldest to Newest
  • Newest to Oldest
  • Most Votes
Reply
  • Reply as topic
Log in to reply
This topic has been deleted. Only users with topic management privileges can see it.
  • W Offline
    W Offline
    wangier
    wrote on last edited by
    #1

    The DataGrid support multi-selection operations. But when I have multi-selected some rows, How can I determine which rows have been selected?

    H 1 Reply Last reply
    0
    • W wangier

      The DataGrid support multi-selection operations. But when I have multi-selected some rows, How can I determine which rows have been selected?

      H Offline
      H Offline
      Heath Stewart
      wrote on last edited by
      #2

      Create a collection of some type (like an ArrayList), then enumerate the rows in your DataGrid. You can do this using the BindingContext of the DataGrid to get the CurrencyManager which associates rows in the DataSource to their displayed rows (since sorting or filtering may change index mapping). For each row index, you can call DataGrid.IsSelected, passing the row index. If true, add to the collection of selected rows. The only real question is whether or not multiple rows are truly selected (i.e., they make look it but their state is a matter of the DataGrid's implementation). I don't know why there isn't a much easier way (like with the ListView). Perhaps MS thought it wouldn't be oft-used enough to warrant the resources. Of course, this could be said about a lot of things in the .NET 1.x BCL! :mad:

      -----BEGIN GEEK CODE BLOCK----- Version: 3.21 GCS/G/MU d- s: a- C++++ UL@ P++(+++) L+(--) E--- W+++ N++ o+ K? w++++ O- M(+) V? PS-- PE Y++ PGP++ t++@ 5 X+++ R+@ tv+ b(-)>b++ DI++++ D+ G e++>+++ h---* r+++ y+++ -----END GEEK CODE BLOCK-----

      1 Reply Last reply
      0
      Reply
      • Reply as topic
      Log in to reply
      • Oldest to Newest
      • Newest to Oldest
      • Most Votes


      • Login

      • Don't have an account? Register

      • Login or register to search.
      • First post
        Last post
      0
      • Categories
      • Recent
      • Tags
      • Popular
      • World
      • Users
      • Groups