Re: wxGrid with single row selection

Fulvio Senore <[email protected]>
Newsgroups gmane.comp.lib.wxwindows.general
Message-ID <[email protected]>
Il 29/08/2023 02:44, Kenneth Porter ha scritto:
> Is there a way to disable multiple selection and use wxGrid to choose a 
> single row?
> 
> I found this discussion on ways to override wxGrid's mouse event 
> handlers. Is there a better way?
> 
> https://stackoverflow.com/questions/9378977/how-to-disable-multi-selection-in-a-wxgrid
> 

I did it many years ago for a large program still in use.
I don't remember how I solved the problem, but looking at the source 
code it looks like I handled the wxEVT_GRID_RANGE_SELECT event.

here is the code:

void fsDataGridRO::OnRangeSelect( wxGridRangeSelectEvent& event )
{
     event.Skip();

     if( m_MultiRowSelect ) {
         return;
     }

     if( event.Selecting() && (event.GetTopRow() == 
event.GetBottomRow()) ) {
         // here if a row is selected: move the cursor to the same row
         if( !m_InSingleLineSelect ) {
             m_InSingleLineSelect = true;
             if( (GetGridCursorRow() >= 0) && (GetGridCursorRow() != 
event.GetTopRow()) ) {
                 SetGridCursor( event.GetTopRow(), GetGridCursorCol() );
             }
             m_InSingleLineSelect = false;
         }
     }

     if( event.Selecting() && (event.GetTopRow() != 
event.GetBottomRow()) ) {
         if( !m_InRangeSelect ) {
             m_InRangeSelect = true;
             SelectRow( GetGridCursorRow() );
             m_InRangeSelect = false;
         }
     }
}


Note the m_InSingleLineSelect and m_InRangeSelect variables: they are 
class members used to avoid recursion.

Fulvio Senore

-- 
Please read https://www.wxwidgets.org/support/mlhowto.htm before posting.
--- 
You received this message because you are subscribed to the Google Groups "wx-users" group.
To unsubscribe from this group and stop receiving emails from it, send an email to [email protected].
To view this discussion on the web visit https://groups.google.com/d/msgid/wx-users/bb5da757-2ded-8459-cceb-5d37833074f7%40fsoft.it.
lmpx.com only provides a reader for public news (NNTP) servers. It is not affiliated with the servers or forums shown here and is not responsible for the content of articles, which is written by their respective authors.