locked
Geting selected row number out of collection (for example Box 3/6) RRS feed

  • Question

  • Hi,

    I need help with getting the row number out of collection.

    My example is as follows:

    I have one master record with assigned 6 details. For example if i have 6 details (boxes), i want to select one box (lets say third box) and print a sticker for box 3/6.

    How can i get number which row is selected?


    Wednesday, October 1, 2014 7:37 AM

Answers

  • Found a solution thanks to this post http://social.msdn.microsoft.com/Forums/vstudio/en-US/52aef7b0-b09f-46e6-b8bd-b7737242b08c/get-selectedindex-from-gridviewlist?forum=lightswitch and the solution offered from Derek.

    I created a property with name BoxNumber and on collectionName_SelectionChanged() used this code to fill it

    int index = collectionName.ToList().IndexOf(collectionName.SelectedItem);
    this.BoxNumber = index + 1;

    • Marked as answer by DarioOs81 Wednesday, October 1, 2014 11:06 AM
    Wednesday, October 1, 2014 9:11 AM

All replies

  • Hi!

    Not sure that I understand correctly, but your detail should have unique ID.. also if you don't have multi-select, selected row is "selected item".. hope that helps..

    Kivito


    Nobody expects the Spanish Inquisition! (M.P.F.C.)

    Wednesday, October 1, 2014 9:07 AM
  • Found a solution thanks to this post http://social.msdn.microsoft.com/Forums/vstudio/en-US/52aef7b0-b09f-46e6-b8bd-b7737242b08c/get-selectedindex-from-gridviewlist?forum=lightswitch and the solution offered from Derek.

    I created a property with name BoxNumber and on collectionName_SelectionChanged() used this code to fill it

    int index = collectionName.ToList().IndexOf(collectionName.SelectedItem);
    this.BoxNumber = index + 1;

    • Marked as answer by DarioOs81 Wednesday, October 1, 2014 11:06 AM
    Wednesday, October 1, 2014 9:11 AM
  • Yes it has. Unike id i use to pass to url (when generating printout) to select the proper box but i also needed to get row count of the collection so when i print label for each box to say box x/y . so my url looks like boxid=z&boxnumber=x so i get what i need. Thank you for your time.
    Wednesday, October 1, 2014 11:11 AM