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?

[Webinar] Streamline your web hosting managementRegister Today

x
 
Jaime OlivaresConnect With a Mentor Software 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
 
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
All Courses

From novice to tech pro — start learning today.