PDA

View Full Version : Onde datatable with difirent cursors



zlatko
28th April 2006, 09:54
I have one datatable object and want in diffirent cases show results from diffirent sql cursors..is that good way? I try it but it doesnt work,becouse after first showing i cannot add another columns and delete previous for second showing..



void QFormAdmin::OnPhysicTbPressed(int nId)
{
int nCols = dtMain->numCols();
int nRows = dtMain->numRows();

// try to clean data table
for (int i=0; i<nCols; i++)
dtMain->removeColumn(0);

for (int i=0; i<nRows; i++)
dtMain->removeRow(0);

dtMain->repaint();

switch(nId)
{
// виклик редактора гілок
case 1:
{
QSqlSelectCursor* curBr = new QSqlSelectCursor( "SELECT deleted FROM branches");

dtMain->setSqlCursor(curBr,false,true );

dtMain->addColumn("deleted", tr("Імя1"));

dtMain->refresh();
break;
}

// виклик редактора контролерів
case 2:
{
QSqlSelectCursor* curCtl = new QSqlSelectCursor( "SELECT controlers.description,controlers.logical_id,contr olers.physical_id,controlers.active,controlers.bra nch,branches.description AS br_name,branches.port,branches.ip_address FROM controlers \
LEFT JOIN branches ON controlers.branch = branches.id");

dtMain->setSqlCursor(curCtl,false,true );

dtMain->addColumn("description", tr("Імя"));
dtMain->addColumn("logical_id", tr("Логічний №"));
dtMain->addColumn("physical_id", tr("Фізичний №"));
dtMain->addColumn("active", tr("Активний"));
dtMain->addColumn("br_name", tr("Імя вітки"));
dtMain->addColumn("port", tr("Порт"));
dtMain->addColumn("ip_address", tr("IP-адрес"));

dtMain->refresh();
break;
}
}
}


After first call i have case 1 and see one columns in datatable. After second call i have case 2: and i create 7 columns but i see one previous column with new data :confused:
Any suggestions pls...

jacek
28th April 2006, 11:44
Try:

void QFormAdmin::OnPhysicTbPressed(int nId)
{
// Do, or do not. There is no try. ;)
const int nCols = dtMain->numCols();
for (int i=0; i<nCols; i++) {
dtMain->removeColumn(0);
}

switch(nId)
{
// виклик редактора гілок
case 1:
{
QSqlSelectCursor* curBr = new QSqlSelectCursor( ... );

dtMain->setSqlCursor(curBr,false,true );

dtMain->addColumn("deleted", tr("Імя1"));

dtMain->refresh( QDataTable::RefreshAll );
break;
}

// виклик редактора контролерів
case 2:
{
QSqlSelectCursor* curCtl = new QSqlSelectCursor( ... );

dtMain->setSqlCursor(curCtl,false,true );

dtMain->addColumn("description", tr("Імя"));
...
dtMain->addColumn("ip_address", tr("IP-адрес"));

dtMain->refresh( QDataTable::RefreshAll );
break;
}
}
}

zlatko
28th April 2006, 12:42
Emm..my stupid thoughtlessness :)
Ok thanks its work perfect with remove :)