Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Sign InSign Up

The Archive Base

The Archive Base Logo The Archive Base Logo

The Archive Base Navigation

  • SEARCH
  • Home
  • About Us
  • Blog
  • Contact Us
Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • Add group
  • Groups page
  • Feed
  • User Profile
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Buy Points
  • Users
  • Help
  • Buy Theme
  • SEARCH
Home/ Questions/Q 7181511
In Process

The Archive Base Latest Questions

Editorial Team
  • 0
Editorial Team
Asked: May 28, 20262026-05-28T17:34:23+00:00 2026-05-28T17:34:23+00:00

This doesn’t seem to be as simple as I’d hoped: Using wxWidgets (2.8 stable

  • 0

This doesn’t seem to be as simple as I’d hoped:

Using wxWidgets (2.8 stable series), I have a wxGrid (not subclassed) with a custom “data adapter” as a wxGridTableBase-derived class.

wxGrid* grid = new wxGrid (this, ID_TABLE);
grid->SetTable (new TableAdapter (foo, bar, baz));
grid->EnableEditing (false);
sizer->Add(grid, wxSizerFlags (1).Expand());

The “simple” thing that I can’t find is a way to refresh the grid when the underlying data model changes. Simply calling wxWindow::Update (pGrid->Update()) is apparently insufficient to actually get the grid to call the underlying wxGridTableBase implementation?

wxGrid* const grid = (wxGrid* const) FindWindow (ID_TABLE);
if (NULL != grid) {
     grid->Update ();
     grid->AutoSizeColumns ();
}

In particular, this grid is acting as a list, and will have rows added and removed from it asynchronously, by either the same or (potentially) another process — it’s a shared data list that can be updated by any one of several networked systems. The grid/list itself is effectively read-only; other controls are used to add and remove items, and each row has one boolean-type attribute that can be toggled as well.

It seems that new rows aren’t added to the view, and deleting rows will cause intermittent SEGV’s in the wx drawing code.

Due to the dynamic/asynchronous updating mechanism, I’m hoping to avoid having to delete and re-add the grid to the window constantly, as I’m sure that will cause all sorts of flicker and nastiness… so, I’ll fall back on trying something brute-force like that, if I absolutely must, but I’d strongly prefer to avoid it.

Unfortunately, despite being flagged as the “stable version,” the wxGrid documentation appears to mostly consist of Yet to be written tags.

Updated:
I’m becoming suspicious that this is a layout-of-container problem. In drawing the grid, the bottom of the grid (last row) can actually overlap both the wxStaticBox frame around its section of the wxFrame window, as well as part of the status line of the frame. Adding and removing rows doesn’t seem to force a re-layout of the container; I’m experimenting with trying to call Layout and the like. Ideally, this should be a scrolling region, but the wxGrid should still be “constrained” within its containing Sizer.

The layout consists, effectively, of a static box, containing a vertical box, the first element of which is a horizontal box of buttons, then the grid, as so:

    --[ Static Box ]------------------------
   |                                        |
   | [Button] [Button] [Button]             |
   |                                        |
   |  -----------------------------------   |
   | |      |   A      |   B   |    C    |  |
   | |-----------------------------------|  |
   | |    1 |   1a     |   1b  |    1c   |  |
   |  -----------------------------------   |
   |                                        |
    ----------------------------------------

Unfortunately, company policy prohibits me from posting screenshots 🙁

If it matters, this is (presently) wxGTK-2.8.12 on Fedora 16 (x86_64), although I’m seeing identical behaviour on CentOS5/RHEL5 using the EPEL (Fedora) packages.

  • 1 1 Answer
  • 0 Views
  • 0 Followers
  • 0
Share
  • Facebook
  • Report

Leave an answer
Cancel reply

You must login to add an answer.

Forgot Password?

Need An Account, Sign Up Here

1 Answer

  • Voted
  • Oldest
  • Recent
  • Random
  1. Editorial Team
    Editorial Team
    2026-05-28T17:34:23+00:00Added an answer on May 28, 2026 at 5:34 pm

    After much experimentation, it looks like the “correct” way to force a refresh goes something like this:

    bool
    CDynamicWxGridTable::AppendRows(const size_t IGNORED _)
    {
       wxGrid *grid = GetView();
    
       if (pGrid != NULL)
       {
          const int iNumRecords = GetNumberRows();
          const int iGridRows = grid->GetNumberRows();
          const int iNeedRows = iNumRecords - iGridRows;
    
          if (iNeedRows)
          {
             grid->BeginBatch();
             grid->ClearSelection();
    
             if (grid->IsCellEditControlEnabled())
             {
                grid->DisableCellEditControl();
             }
    
             {
                wxGridTableMessage pop(this,
                     wxGRIDTABLE_NOTIFY_ROWS_DELETED,
                     0, iGridRows);
                grid->ProcessTableMessage(pop);
             }
             {
                wxGridTableMessage push(this,
                     wxGRIDTABLE_NOTIFY_ROWS_APPENDED,
                     iNumRecords);
                grid->ProcessTableMessage(push);
             }
             grid->AutoSize();
             grid->ForceRefresh();
             grid->EndBatch();
          }
       }
    
       return true;
    }
    
    bool
    CDynamicWxGridTable::DeleteRows(const size_t IGNORED pos,
          const size_t IGNORED rows)
    {
       return AppendRows(0);
    }
    

    These are called during my (5Hz) update routine by grabbing grid and calling its ->AppendRows(1) method, which in turn calls the wxTableBase-derived class’s ::AppendRows member.

    Unfortunately, since I’m drawing from asynchronous, dynamically-updated records, the wxGrid caching system is still “fighting” me as far as row attributes (if a row changes, such that its GetAttr value should change, it doesn’t refresh dynamically, since the above only tests the number of rows that there should be versus the number of rows that actually exist). However, this is a relatively minor bug, and I’m hoping to overcome it through other means.

    The “critical” part seems to be synthesizing the delete/append rows messages to the wxGridTable system through ProcessTableMessage… without which, the wxGrid cache seems to fail to notice the changes in the table size.

    Incidentally, the crashes due to losing rows were alleviated by putting guards in the ::GetValue(const int row, const int column) method to check for valid values:

    if (row < 0 || row > GetNumberRows()) { return L"×"; }
    if (col < 0 || col > LAST_COLUMN) { return L"×"; }
    

    These “×” values don’t ever seem to display, after adding the crazy message-injection logic above, however.

    • 0
    • Reply
    • Share
      Share
      • Share on Facebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Sidebar

Related Questions

This doesn't have to be Java, but it's what I'm dealing with. Also, not
This doesn't seem to be working right now. I'm using Faye with NodeJS behind
This doesn't happen all the time. A bug is not a bug if cannot
This doesn't execute the delimiter (its displayed verbatim in the confirm dialog). Why not?
This doesn't seem to work as I intend. VB.NET: Dim x = Model.Discussions.OrderByDescending(Function(d) d.Messages.OrderByDescending(Function(m)
This doesn't seem to work (compiler complains that Something 's getFoo() method doesn't implement
This doesn't seem to work in jqTouch or iUI. But I know it's possible
This doesn't seem to work. Is it possible? public interface IInterface1 {} public interface
This doesn't seem to be possible? So what is the best work-around? Expando /
This doesn't work. I've got an exception from SQL databse that column does not

Explore

  • Home
  • Add group
  • Groups page
  • Communities
  • Questions
    • New Questions
    • Trending Questions
    • Must read Questions
    • Hot Questions
  • Polls
  • Tags
  • Badges
  • Users
  • Help
  • SEARCH

Footer

© 2021 The Archive Base. All Rights Reserved
With Love by The Archive Base

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.