Selecting PivotItem by Header

Mar 2, 2012 at 10:42 AM
Edited Mar 2, 2012 at 10:42 AM

Hi 

I am trying to select PivotItem by header name

I inserted this in control source code

 

public void SelectPivotItemByName(string headerItem)
        {
            
            if (headerItem == null)
                return;

            // Find the PivotItem whose header was selected
            PivotItem pItem = pivotItems.Where(p => p.PivotHeader.Name.Equals(headerItem)).FirstOrDefault();

            if ((pItem != null) && (pItem != currPivotItem))
            {
                if (currPivotItem != null)
                {
                    currPivotItem.SetActive(false);
                }

                pItem.SetActive(true);
                currPivotItem = pItem;
                
            }

 

}

It works to the extant of selecting the correct header and content

but it does not move the header to first position on the left

with the result the header in the first position does not obviously respond to mouse click

Any suggestions

Ajay

Coordinator
Mar 5, 2012 at 7:32 AM

Hi Ajay,

        As of now the FluidPivotPanel only handled user interactions and performed the animation based on them. Explicit selected through code has not been added yet.

However there is a quick solution for that.

        If you look at the PivotHeaderControl class, it has an event called HeaderSelected, which is fired when the user clicks on the HeaderControl. The Header moves in response to this event. You can extend this class further to add one more API (say SelectHeader) which will raise the event.

public void SelectHeader()
{
    if (HeaderSelected != null)
    {
        HeaderSelected(this, new EventArgs());
    }
}

 Now you can modify your own code like this

public void SelectPivotItemByName(string headerItem)
{
            
            if (headerItem == null)
                return;

            // Find the PivotItem whose header was selected
            PivotItem pItem = pivotItems.Where(p => p.PivotHeader.Name.Equals(headerItem)).FirstOrDefault();

            if ((pItem != null) && (pItem != currPivotItem))
            {
                pItem.PivotHeader.SelectHeader();                
            }
}

Mar 5, 2012 at 2:20 PM

Hi Ritish

thanks

Need to change slightly

 This works like a charm...
 public void SelectPivotItemByName(string headerItem)
        {
            if (headerItem == null)
                return;
            // Find the PivotItem whose header was selected
            PivotItem pItem = pivotItems.Where(p => p.PivotHeader.Name.Equals(headerItem)).FirstOrDefault();
            IPivotHeader header = pItem.PivotHeader as IPivotHeader;
            if (header != null)
            {
                header.SelectHeader();
            }
        }