WxGrid questions

If you are using the main C++ distribution of wxWidgets, Feel free to ask any question related to wxWidgets development here. This means questions regarding to C++ and wxWidgets, not compile problems.
Post Reply
mbeardsley
Knows some wx things
Knows some wx things
Posts: 46
Joined: Thu Sep 25, 2014 7:40 pm

WxGrid questions

Post by mbeardsley » Wed Jan 02, 2019 12:36 am

1) Is there some way to disable all group selection functions? I want to disallow the user from ever having more than one cell selected. For my purposes, the selected cell is the "active item", and it makes no sense for there to be more than one active item.

2) Is there some way to change the color of the top and left grid lines if there are no row and column headers? In the attached image you can see that the lines between cells are red, as set by SetGridLineColour( wxColour( 255, 0, 0 ) ), but the top and left lines are not. I assume that this is because they are actually the right and bottom lines of what would be the row and column headers.

In my case, I am using a grid as an item selection method, and simply want the user to be able to select a single square where each square represents an object for them to choose from.

I am using wxWidgets 3.04 under VisualStudio 2017 - Windows 10.

Thanks.
Attachments
Untitled.png
Untitled.png (3.06 KiB) Viewed 437 times

User avatar
doublemax
Moderator
Moderator
Posts: 14282
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxGrid questions

Post by doublemax » Wed Jan 02, 2019 10:45 am

wxGrid might not be the best choice for what you're doing. How many cells are there at maximum? If there are not too many, you could work with individual controls (e.g. a wxPanel) as cells. Otherwise something custom might be better.
Use the source, Luke!

User avatar
shawnhcorey
Knows some wx things
Knows some wx things
Posts: 34
Joined: Mon Nov 19, 2012 3:29 pm
Location: The Great White North

Re: WxGrid questions

Post by shawnhcorey » Wed Jan 02, 2019 2:33 pm

doublemax wrote:wxGrid might not be the best choice for what you're doing. How many cells are there at maximum? If there are not too many, you could work with individual controls (e.g. a wxPanel) as cells. Otherwise something custom might be better.
Wouldn't you have to use `wxGridSizer` or `wxFlexGridSizer` for layout of the `wxPanel`s?

mbeardsley
Knows some wx things
Knows some wx things
Posts: 46
Joined: Thu Sep 25, 2014 7:40 pm

Re: WxGrid questions

Post by mbeardsley » Wed Jan 02, 2019 2:59 pm

Well, there could be anywhere from like 20 to 2000 (and I won't know how many until runtime).

I thought that by using the wxGrid I could gain a lot of functionality (like scrolling if needed).
It seems that wxGrid has MORE than what I need, I just want to enforce the "one-selected-cell-only" rule.

The top and left side line issue is not a big deal, just an aesthetic item.

I could do a custom control, but I would have to duplicate a lot of functionality I think.

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3573
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: WxGrid questions

Post by ONEEYEMAN » Wed Jan 02, 2019 3:38 pm

Hi,
According to this, such selection mode is not available, most likely because the control mimics the "spreadsheet" BEHAVIOUR.

But you can try to catch some events and disallow selection when it happens.

Thank you.

User avatar
doublemax
Moderator
Moderator
Posts: 14282
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxGrid questions

Post by doublemax » Wed Jan 02, 2019 6:07 pm

Well, there could be anywhere from like 20 to 2000 (and I won't know how many until runtime).
Ok, then using individual controls is not an option (at least not a good one).
I could do a custom control, but I would have to duplicate a lot of functionality I think.
Can you describe in more detail what you actually need / what the control has to do?
Use the source, Luke!

ONEEYEMAN
Part Of The Furniture
Part Of The Furniture
Posts: 3573
Joined: Sat Apr 16, 2005 7:22 am
Location: USA, Ukraine

Re: WxGrid questions

Post by ONEEYEMAN » Wed Jan 02, 2019 6:29 pm

Hi,
The other alternative is to use virtual list control.
But as doublemax said - we need to know what functionality should be there.

Thank you.

mbeardsley
Knows some wx things
Knows some wx things
Posts: 46
Joined: Thu Sep 25, 2014 7:40 pm

Re: WxGrid questions

Post by mbeardsley » Wed Jan 02, 2019 8:15 pm

Basically, I want to show a "grid-like" widget that has a programmable number of boxes. Each box represents an item in the world from 1 to N.

When the user clicks on a box, a frame to the right will be displayed containing the data associated with that item. The user can then view and/or edit that data, until such time as another box is clicked. The right-side frame then gets updated to show/edit the data of the newly selected item.

Functionally, I guess that it is sort of like a compact version of a wxChoice box, where the choices are 1 to N, but you don't have to scroll down through hundreds of items if the list gets long.

I have tried to do the obvious things, like various combinations of capturing wxEVT_GRID_CELL_BEGIN_DRAG and/or wxEVT_GRID_CELL_LEFT_CLICK, and doing a ClearSelection() but that has been either worthless or created a stack overflow due to recursive calls.

I would think that allowing only a single cell to be selected should be an easy thing. There are options for selecting a single row, or a single column, but not a single cell. Seems like an oversight to me.

I appreciate the help though, guys. Thanks.

User avatar
doublemax
Moderator
Moderator
Posts: 14282
Joined: Fri Apr 21, 2006 8:03 pm
Location: $FCE2

Re: WxGrid questions

Post by doublemax » Wed Jan 02, 2019 9:49 pm

That sounds simple enough for a custom control. All you need is a wxPanel with a custom paint event handler where you draw all the boxes according to their state (selected or not). Then in a mouse event handler you check which (if any) box was clicked, then you change its state, generate an event and force a refresh.

For the event you don't even have to define a new one, just re-use an existing one, e.g. wxEVT_LISTBOX.
Use the source, Luke!

mbeardsley
Knows some wx things
Knows some wx things
Posts: 46
Joined: Thu Sep 25, 2014 7:40 pm

Re: WxGrid questions

Post by mbeardsley » Fri Jan 04, 2019 1:00 am

Yeah, that's what I suspect that I'll end up doing.

It just seemed simpler at first glance to use a wxGrid, since it had everything I needed, except for single cell selection.

Thanks.

Post Reply