Click here to Skip to main content
12,952,215 members (62,442 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hello

Env: Win 7 MS Visual Studio 11

I need to select a ribbon category programmatically ...

I use: pMainFrame->m_wndRibbonBar.SetActiveCategory( pMainFrame->m_wndRibbonBar.GetCategory( 3), TRUE);
and this is selecting the right ribbon (index 3, the fourth category of the ribbon) when I run the exe in XP....

But this code selects the second category ( index 2) when used in Windows 7 !!!

Any idea what is the right way to select a given ribbon category ?

Thanks for your help

Thierry
Posted 19-Nov-12 11:38am

1 solution

Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

Hello All

Problem Solved.... The trick is not to use the index but the name of the category...

Here is a function that do that:

int CYourClassName::ActivateCategoryByName( CString strCategoryName)
{
      // Grab Pointer to MainFrame 
	
  CMainFrame* pMainFrame = ( CMainFrame*) AfxGetMainWnd();
 
  // Grab Pointer to RibbonBar
 
  CMFCRibbonBar* pmrb = &pMainFrame->m_wndRibbonBar;
 
  // Get Category Count
		
  int nCategoryCount = pmrb->GetCategoryCount();
 
  // Scan Category
 
  for ( int nCategoryNdx = 0; nCategoryNdx < nCategoryCount; nCategoryNdx++)
  {
    // Grab Pointer to Category
 
    CMFCRibbonCategory* pmrc = pmrb->GetCategory( nCategoryNdx);
 
    // Get Category Name
 
    CString strName = pmrc->GetName();
 
    // Check for Requested Category
 
    if ( strName == strCategoryName)
    {
      pmrb->ShowCategory( nCategoryNdx, TRUE);
 
      pmrb->SetActiveCategory( pmrc, TRUE);		
 
      return nCategoryNdx;
    }
  }
 
  return -1;
}


Thierry
  Permalink  
v2
Comments
Hesam Gholami 9-Sep-13 4:48am
   
I also have this problem,thank u

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 6,239
CHill60 3,490
Maciej Los 3,083
Jochen Arndt 1,975
ppolymorphe 1,880


Advertise | Privacy | Mobile
Web02 | 2.8.170525.1 | Last Updated 17 Feb 2013
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100