wxGrid or wxListCtrl

Thibault Genessay tibogens at gmail.com
Wed Apr 16 00:01:16 PDT 2008


Hi szurilo

On Wed, Apr 16, 2008 at 8:24 AM, szurilo <szurilo at sch.bme.hu> wrote:
>  > What do you mean under 'virtual storage'? Can you give me a link where i
>  > can looking forward to it?

For the list control, you use the wxLC_VIRTUAL style. Have a look at
the docs to see how it works, but basically what you have to provide
is a function that returns the value for row X column Y each time
wxWidgets needs it (derive a class from wxListCtrl and implement
OnGetItemText())

>
> >
>  >> 2. I have to refresh about 50 records per second, which one is able to
>  >> it,
>  >> beside i dont want any freezing or vibrating effect?
>  >
>  > I don't know about wxListCtrl, but you can Freeze/Thaw the grid and
>  > update all at once without redrawing.
>  >
>  > So i can update only one item if i want it, isnt it?

When you use a virtual list control, the list does not know when your
data changes. To inform it that something changed, you can call
RefreshItem(), this will call again your function querying back for
the updated data. The refresh does not create any kind of flickering.

>
> >
>  >> 3. I also want some trivial thing like to scroll among these records
>  >> while
>  >> the GUI refreshing records.
>  >
>  > Use two threads.

That's a strange advice for several reasons:
1) wxWidgets does not like it at all when two threads access the GUI.
Not only wxWidgets but also the underlying windowing system (Windows,
GTK,...). There have been lots of discussions regarding multithreading
recently. The conclusion is always the same: do *never* use multiple
threads with the GUI. Of course, worker threads can coexist with the
GUI thread, but only one thread must access the GUI. So "refreshing"
the GUI from another thread is absolutely not an option.
2) You don't even need threads for that. The user can scroll when the
list is being refreshed. There is absolutely no need to do anything
special about it. The user scrolls, wxWidgets queries for the data -
all of this occurs in the same thread without a problem.

You could need to use threads if you wanted to update your data
storage (i.e. the place where your data is actually stored, and where
you look for you data when wxWidgets asks you for it) asynchronously.
But remember that if you do so, you must protect your data with a
mutex (or implement a finer-grained - per-block-of-rows, for instance
- locking mechanism). There is a performance issue here if you don't
implement that feature carefully.

>  > This is also very hard to me, since i have never used more than 1 thread,
>  > i know its a must dont laugh me. Pls give me a hint about it. Is there any
>  > class in wxWidgets that helps me create new threads? Actually i know
>  > boost(c++ library) can do it, but i never see it in wxWidgets.

wxThread ?

> >
>  >> If you suggest the wxListCtrl pls let me know which format is good for
>  >> me:
>  >> report view, list view, etc.

If you decide to go for the wxListCtrl, you must use the wxLC_REPORT
mode as it is the only one allowed for virtual lists.

>  >
>  > What kind of items are you going to show?
>  >
>  > Mostly text(strings and numbers). But it needs to show a small picture or
>  > an animation in each records.
>  > Animation could be a wxGauge or a function diagramm.
>
> >
>  >> I dont know much about wxGrid but if you think this one will be the best
>  >> for
>  >> me than iam also interested in.
>  >
>  > How much is 'much more than 1000'? 2000? 10000? 1000000?
>  > Are all of those going to have pictures/animations,etc?
>  >
>  > Actually the more the best wxWidgets can handle it. But i think usually
>  > the needs are between 1-10000 records.
>  > And yes. If its ok, i would like to place an image in every records.

If you implement it, wxListCtrl::OnGetItemImage() expects a index into
an image list. So your items can have images, but those images must be
pre-loaded in an image list bound to your wxListCtrl. If you want
dynamic images then(i.e. images that are not known until the item is
fetched from the data storage) I'm afraid you would have to do it
yourself.

Regards

Thibault


More information about the wx-users mailing list