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
345
Cell selection through code behind
posted

Hi,

I'm unable to programmatically set cell focus on a XamPivotGrid (v12.1). I'm using a custom XamPivotGrid object deriving from XamPivotGrid, within this class I have a SetFocus() method which should programmatically set the focus on a cell. Here is a code snippet of where I got stuck:

public void SetFocus(object cellRecord)
{
 bool success = this.Focus();
 foreach (PivotDataRow row in this.GridLayout.Rows)
 {
  foreach (PivotCell cell in row.Cells)
  {
   ICell c = cell.Data as ICell;
   if (c != null)
   {
    List<object> records = GetRecords(c);
    foreach (object record in records)
    {
     if (record == cellRecord)
     {
      // bool s = this.SelectCell(cell, PivotInvokeAction.Click); // Note: this doesn't work, always returns false
      // TODO: set focus on cell here
      return;
     }
    }
   }
  }
 }
}
private List<object> GetRecords(ICell cell)
{
 List<object> records = new List<object>();
 if (cell != null)
 {
  FlatDataSource flatDataSource = this.DataSource as FlatDataSource;
  if (flatDataSource != null)
  {
   foreach (int index in flatDataSource.GetCellItemsIndexes(cell))
   {
    records.Add(flatDataSource.GetRecord(index));
   }
  }
 }
 return records;
}

When I run this code I get to the TODO comment (so I find the correct cell), but I'm not able to set the focus on the cell. I've tried SelectCell, SetActiveCell and setting IsActive and IsSelected to true. SelectCell and SetActiveCell always return false, setting the "Is" flags has no visual effect.

Can you please have a look and let me know what I'm missing?

Regards,

Roman

 

Parents
No Data
Reply
  • 345
    posted

    After some further analysis, I think it would be most useful if you can show me a working example where you have UI focus on a cell, then do a flatdatasource refresh by setting the ItemSource to null and then setting it to the original observable collection, and then setting UI focus on the cell which was focused before the refresh.

    I can't get this to work :(

Children