Your Privacy Matters: We use our own and third-party cookies to improve your experience on our website. By continuing to use the website we understand that you accept their use. Cookie Policy
65
Setting the ActiveRecord
posted

 Hi,

sometimes when I set the ActiveRecord of the Grid, the Grid selects the wrong record... It seems that the error occures after I selected the last record and then go up the list, step by step... 

Sample:
I have 50 records and select the last, then I go back by setting the ActiveRecord Property, at the 20th record it doesn't go to record no. 19! Instead it goes to the 50 one...

The RecordActivating Event triggers 4 to 5 times for this step!

BTW: the position of the record where the error occures seems to depend on the height of the grid.

 

Kind Regards
Florian Sundermann

  • 1650
    posted

     Hi Florian,

    I've had some issues with that property as well. The utility method below might be somewhat redundant for the next release (7.2 Beta is over 2 months old, if I recall correctly), but does it's job ok for now:

     

        /// <summary>
        /// Selects and activates a given record of a grid.
        /// </summary>
        public static void SelectRecord(XamDataGrid grid, Record record)
        {
          //remove current selections
          grid.SelectedItems.Records.Clear();

          grid.ActiveRecord = null;
          grid.ActiveRecord = record;
          record.IsSelected = true;
        }

     

        /// <summary>
        /// Select the <see cref="DataRecord"/> that represents a given
        /// data item.
        /// </summary>
        /// <param name="grid">The grid to be processed.</param>
        /// <param name="dataItem">The bound item to look for.</param>
        /// <returns>True if the grid provides any records which could be
        /// selected. If the grid is empty, false is returned.</returns>
        public static bool SelectRecordForItem(XamDataGrid grid, object dataItem)
        {
          DataRecord record = grid.GetRecordFromDataItem(dataItem, false);
          if (record != null)
          {
            SelectRecord(grid, record);
            return true;
          }
          else
          {
            return false;
          }
        }

     

    Hope it'll work. Cheers!

    Philipp