Grid Cleaning Topic is solved

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
rodrigorpb
Earned a small fee
Earned a small fee
Posts: 11
Joined: Thu Apr 17, 2008 7:49 pm

Grid Cleaning

Post by rodrigorpb » Fri Jul 25, 2008 12:09 am

Hello,

I have a frame that makes data insertion into a database, with a grid that shows this data. This grid must be updated:
- when the frame is shown;
- when "record" button is pressed and recording occur succesfully;

For this, I need also to clear the grid, before updating it.

Take a look:

This is the function that execs a sql selection command and distribute the data extracted from database to the grid:

Code: Select all

void CadCidade::SelecionarGrid()
{
  Grid1->ClearGrid();
  conecta* objgrid = new conecta();

  PGresult *resGrid;
  resGrid = PQexec(objgrid->conn, "select * from cadcidade");

  int numlinha = PQntuples(resGrid);
  int numcoluna = PQnfields(resGrid);

  Grid1->InsertRows(1, numlinha, true);

  for (int y = 0; y < numcoluna; y++)
  {
    int x = 0;
    for ( x = 0; x < numlinha; x++)
    {
      char* valor = PQgetvalue(resGrid, x, y);
      wxString valorS(valor, wxConvISO8859_1);
      Grid1->SetCellValue(x,y, valorS);
    }
  }
}
And I also call SelecionarGrid() inside constructor, so the frame will be showed with grid updated properly.

This code I posted is not working correctly. After recorded the data, the number os lines becomes duplicated and the new record only appears when the frame is showed again. I think ClearGrid() is not in the right place, or I`m using it wrong way.

Can anyone help me?

Thanks everybody!!

timg
Earned some good credits
Earned some good credits
Posts: 148
Joined: Mon Jan 23, 2006 6:52 pm

Post by timg » Fri Jul 25, 2008 12:18 am

I think ClearGrid() doesn't do what you think it does. It only clears the cells values, it doesn't delete all the rows.

I think you probably want to delete all your current rows rather than clear the grid.

Also, you probably want to call wxGrid::ForceRefresh() after you have updated the grid with all the new data.

Post Reply