ListView-SetExtendedStyle question

I am using a list view and when the listview is created I am giving it 2 extended style properties:

ListView_SetExtendedListViewStyle( m_pListView->m_hWnd,
                                  LVS_EX_FULLROWSELECT|
              LVS_EX_GRIDLINES);

I want to add function in the MainFrame's Menu to turn off and on the Gridlines style: this is what i am using:

void CGeoView::OnViewGridlines()
{
      
      if(m_pListView->GetExtendedStyle()==LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES)
      {
            m_pListView->SetExtendedStyle(LVS_EX_FULLROWSELECT);
      }
      
      {
            if(m_pListView->GetExtendedStyle() ==  LVS_EX_FULLROWSELECT  )
            m_pListView->SetExtendedStyle(  LVS_EX_FULLROWSELECT |LVS_EX_GRIDLINES );
      }
      
}

What this does is when the Listview is first created, it has fullrowselect and gridlines styles, but when selecting OnViewGridlines() function from the menu, the grids will turn off, and then re-appear immediately. how can I set this function to turn off the gridlines (but keep the fullrowselect style) when selecting that menu option, and turn back on the next time selecting that menu option?( Just like the show/hide toolbars function, under the View-Toolbars menu).
cheapstrAsked:
Who is Participating?
I wear a lot of hats...

"The solutions and answers provided on Experts Exchange have been extremely helpful to me over the last few years. I wear a lot of hats - Developer, Database Administrator, Help Desk, etc., so I know a lot of things but not a lot about one thing. Experts Exchange gives me answers from people who do know a lot about one thing, in a easy to use platform." -Todd S.

Jaime OlivaresSoftware ArchitectCommented:
Just have to do this:

void CGeoView::OnViewGridlines()
{
     
     if(m_pListView->GetExtendedStyle() & LVS_EX_GRIDLINES)
          m_pListView->SetExtendedStyle(LVS_EX_FULLROWSELECT);
     else
          m_pListView->SetExtendedStyle(  LVS_EX_FULLROWSELECT | LVS_EX_GRIDLINES );
}
0

Experts Exchange Solution brought to you by

Your issues matter to us.

Facing a tech roadblock? Get the help and guidance you need from experienced professionals who care. Ask your question anytime, anywhere, with no hassle.

Start your 7-day free trial
Jaime OlivaresSoftware ArchitectCommented:
In fact, the problem is the missing "else". You toggles the flags twice because of this.

Notices the use of the & operator simplifies the if statement.
0
cheapstrAuthor Commented:
sorry, i must have typed the function in wrong, actually there was an else in there, but it didnt work. but perhaps i didndt need that 2nd if statement? anyhow, your solution worked so thanks. What does the '&' character in:  if(m_pListView->GetExtendedStyle() & LVS_EX_GRIDLINES) do? I know you said it simplifies it, could you explain?
0
Jaime OlivaresSoftware ArchitectCommented:
Style is a combinations of many "flags", every style is a different bit in Style word.
The & (bitwise and operator) evaluates if an specific bit (or group of bits) is ON. So you don't have to know all possible combinations to know that a specific style is present.
Good luck,
Jaime.
0
It's more than this solution.Get answers and train to solve all your tech problems - anytime, anywhere.Try it for free Edge Out The Competitionfor your dream job with proven skills and certifications.Get started today Stand Outas the employee with proven skills.Start learning today for free Move Your Career Forwardwith certification training in the latest technologies.Start your trial today
System Programming

From novice to tech pro — start learning today.