Help with Dynamically changing a Control's parent
Hi All.
I have use for the ability to Dynamically Change a Control's parent similar to the one in the examples. I have been able to fill the txtTextbox with data from the data base and also created a click event so that when any Textbox item is clicked one item is moved from the left panel to the right panel. It works exactly like the example when an item is clicked.
My question is this:
What is the code that will allow the " MoveTextbox($strFormId, $strControlId, $strParameter)" to cause the particular item clicked to be moved instead of simply moving the highest item from one panel to the other.
Just haven't grasped what to pass to the function. Perhaps there is another example I could look at that would help
Thanks in advance.
David

To move item that is clicked you could do something like this for every control that you want to be movable:
<?php$txtTextbox = new QTextBox($this->pnlLeft);
$txtTextbox->AddAction(new QClickEvent(), new QAjaxAction('MoveMe'));
?>
and then create function:
<?phpprotected function MoveMe($strFormId, $strControlId, $strParameter) {
$objChildControl = $pnlSource->GetChildControl($strControlId);
$objChildControl->SetParentControl($this->pnlRight);
// to disable any more moves to this control remove all actions
$objChildControl->RemoveAllActions(QClickEvent::EventName);
}
?>
Hi Dugokontov
Thanks for the reply.
I create the items (textboxes) to be moved from a DB "load all" which means that I would need to create multiple functions. I really need to see if I can pass the "moveMe" as a variable to a single function.
David
You can set the ActionParameter of the textboxes to moveMe..?
i guess I'm still not sure what you are asking..
There is no need to pass action parameter. All your controls can call the same method. The second parameter of event functions, $strControlId, will point out which of many controls invoke "click" event.
For example
<?php$btnEdit = new QButton($this);
$bntEdit->AddAction(new QClickEvent(), new QAjaxAction('Click_event'));
$btnAdd = new QButton($this);
$bntAdd->AddAction(new QClickEvent(), new QAjaxAction('Click_event'));
?>
Both of these buttons call same event. But, in event, you can identify which control called it by its second parameter -> $strControlId;
Best regards
Thanks dugokontov
I have it working well I can move items from the left panel to the right panel and back
Code (not pretty) for doing it is below But I have one other thing to figure out. At Save time I need to determine what controls has been place in the right panel and pick ->Text from that control.
Can you also help me with this?
Thanks
Dave
$boxnum = null;
$objavailablepageArray = Page::LoadAll();
foreach($objavailablepageArray as $objavailablepage) {
$boxnum++;
// The parent must be the panel, because the panel is going to be responsible
// for rendering it.
$this->txtTextbox[$boxnum] = new QTextBox($this->pnlLeft);
$this->txtTextbox[$boxnum]->Text = sprintf('%s', $objavailablepage);
$this->txtTextbox[$boxnum]->Width = 250;
$this->txtTextbox[$boxnum]->AddAction(new QClickEvent(), new QAjaxAction('MoveMe'));
$this->txtTextbox[$boxnum]->ActionParameter = 'right';
}
}
protected function MoveMe($strFormId, $strControlId, $strParameter) {
if ($strParameter == 'left') {
$pnlSource = $this->pnlRight;
$pnlDestination = $this->pnlLeft;
$newsource = 'right';
} else {
$pnlSource = $this->pnlLeft;
$pnlDestination = $this->pnlRight;
$newsource = 'left';
}
// Get the Source's Child Controls
$objChildControl = $pnlSource->GetChildControl($strControlId);
$objChildControl->ActionParameter = $newsource;
$objChildControl->SetParentControl($pnlDestination);
This should be less complicated than previous one (:
Just use
<?php$this->pnlRight->GetChildControls();
?>
and it will return an array of controls in Right panel. So, you can than iterate through it with foreach.
<?phpforeach($this->pnlRight->GetChildControls() sa $objControl) {
if ($objControl instanceof QTextBox) { // use this if panel can have some other controls other than QTextBox
$strMyText = $objControl->Text;
}
}
?>
Best regards