Can't select first column in wxGrid

Are you writing your own components and need help with how to set them up or have questions about the components you are deriving from ? Ask them here.
Post Reply
stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Can't select first column in wxGrid

Post by stegemma » Fri Dec 28, 2012 9:27 am

I have a component derived from wxGrid and i use wxGridTableBase to handle grid contents. My grid component only bind this events:

Code: Select all

Bind(wxEVT_GRID_SELECT_CELL, &clsWxGrid::OnSelectCell, this);
Bind(wxEVT_GRID_COL_SIZE, &clsWxGrid::OnGridColSize, this);
The problem is that my project use some of this grid components and the most of them works fine but a couple of them do a strange thing: the wxEVT_GRID_SELECT_CELL was not fired if you click on a cell in the first column of the grid.

I checked the working grids against the bad ones but find no difference at all. Even if i add binding for wxEVT_GRID_CELL_LEFT_CLICK i get that this event will not be fired for the cell in first column.

If i select with mouse the cell in second column and then use keyboard arrows, the cursor moves correctly even to first cell and i can edit, so it seems that only mouse clicking has some problem.

This problem is very urgent... i have to write my own grid component, if i can't solve it. Any suggestion on where to look, to find a solution?

Thanks.

PS: wxWidgets 2.9.4 on Windows Platform, UNICODE build, Codelite IDE, G++

After some investigation i think that the problem could be related to HideCol function that i use to hide some id columns (before the ones that doesn't works); i use it even in working grids... so there must be something wrong in certain circumstances...

stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Re: Can't select first column in wxGrid

Post by stegemma » Fri Dec 28, 2012 10:05 am

I've found the point in grid.cpp where it fails:

Code: Select all

int wxGrid::PosToLinePos(int coord,
                         bool clipToMinMax,
                         const wxGridOperations& oper) const
[...]

// check if the position is beyond the last column
    const int lineAtMaxPos = oper.GetLineAt(this, maxPos);
    if ( coord >= lineEnds[lineAtMaxPos] )
        return clipToMinMax ? maxPos : -1;
It seems that lineEnds contains bad values, if you hide columns, so that when you click near to the start of the first cell then the wxGrid can't find the right column. If you resize first visible column and then click near to the end of the first cell... the mouse event works! It seems a wxGrid bug, to me, anybody experienced that bad behaviour?

stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Re: Can't select first column in wxGrid

Post by stegemma » Fri Dec 28, 2012 10:32 am

Sorry to have to reply to myself, but i have posted a simple project to reproduce the bug:

http://www.getfile.org/public/GridBug.zip

You can do it by yourself, just create a dialog with a grid and then add this row to your MainDialog costructor:

Code: Select all

m_grid->HideCol(0);
Run it and try to click to column B row 1, near to the left of the cell: nothing happens; try to click near to the right of the same cell and it works.

If it happens even to you, how can we submit this bug to developers? Any work-around?

stegemma
Earned a small fee
Earned a small fee
Posts: 16
Joined: Mon May 11, 2009 3:15 pm
Contact:

Re: Can't select first column in wxGrid

Post by stegemma » Fri Dec 28, 2012 11:22 am

Finally, here's my work-around to this problem:

instead of HideCol(col) i use:

Code: Select all

SetColMinimalAcceptableWidth(0);
SetColSize(col, 0);
Not very good because user can expand hidden columns... but it looks as that columns are hidden and for now it's good enough, for me.

Post Reply