Skip to main content

How to: Focus a Card that is not Displayed on the Current Page

The following example moves focus to a card that is not displayed on the current page. First, switch to the page that contains the required card, and then move the card focus.

protected void Button1_Click(object sender, EventArgs e)
{
    // Obtain the visible index of the required card.
    int cardIndex = ASPxCardView1.FindVisibleIndexByKeyValue("OLDWO");
    if (cardIndex == ASPxCardView.InvalidCardIndex) return;
    if (!IsCardVisibleOnScreen(cardIndex)) {
        // Switch to the page that contains the required card.
        GoToPage(cardIndex);
    }
    // Focus the required card.
    ASPxCardView1.FocusedCardIndex = cardIndex;
}

bool IsCardVisibleOnScreen(int cardIndex)
{
    int startIndex = ASPxCardView1.PageIndex * ASPxCardView1.SettingsPager.PageSize;
    int endIndex = startIndex + ASPxCardView1.SettingsPager.PageSize;
    return cardIndex >= startIndex && cardIndex < endIndex;
}
void GoToPage(int cardIndex)
{
    ASPxCardView1.PageIndex = cardIndex / ASPxCardView1.SettingsPager.PageSize;
}