How to handle buttonclicked event of DDDW? - button

Situation:
I have a button in my DDDW and i want to capture buttonclicked event.
Problem:
when i click on the button in DDDW the buttonclicked event of DW Control is not fired and ItemChanged event is fired for DW control.
Question:
How do i capture buttonclicked event for the button in DDDW? Or is there any other way i can delete a row from DDDW when delete button is clicked for a particular row?
PowerBuilder 12.5

According to the PB help, a DataWindowChild has no events :|
But, that doesn't mean we still can't hook into it via the DW control's itemchanged event. Note: this is a hack, and underwent some very-limited testing. But, it demonstrates a point, I guess.
Here's what I did:
Created a DataWindow with the code and name columns, and a computed field (for the red X) named delete_button
Created another DataWindow and painted that DW as a DDDW on there, named profession
In my window control's open event, I got the DDDW from the DW and stuck it in an instance variable:
dw_1.GetChild("profession", REF idwc_profession)
Then, coded the itemchanged event for the DW control:
// dw_1::itemchanged
//
// - DDDW is named "profession"
IF dwo.Name = "profession" THEN
IF IsValid(idwc_profession) THEN
string ls_clickedobject
// Get the DataWindowCHILD object where the pointer was clicked:
ls_clickedobject = idwc_profession.GetObjectAtPointer()
IF IsNull(ls_clickedObject) OR (ls_clickedobject = "") THEN RETURN
// Return from GetChild is <column name>~t<row number>; let's get
// the position of the tab character so we can parse it
long ll_tabPos
ll_tabPos = Pos(ls_clickedObject, "~t")
IF ll_tabPos > 0 THEN
string ls_clickedDddwColumn
ls_clickedDddwColumn = Trim(Left(ls_clickedObject, ll_tabPos - 1))
// Check to see if we've clicked on the computed field with the delete button
IF Lower(ls_clickedDddwColumn) = "delete_button" THEN
long ll_clickedDddwRow
// grab the row we want to delete
ll_clickedDddwRow = Long(Trim(Right(ls_clickedObject, Len(ls_clickedObject) - ll_tabPos)))
IF ll_clickedDddwRow > 0 THEN
// delete the row from the DDDW
idwc_profession.DeleteRow(ll_clickedDddwRow)
SetNull(data) // reset our data
END IF
END IF
END IF
END IF
END IF
RETURN
Also note that you may have to play around with the return value from itemchanged to get it to do what you want. And, if you want to automatically dropdown the DDDW again after the deletion happens, you'd might be able to use the Send() method to do so (I don't know the right "number" for that, though).

Related

How to fix Maximum call stack size exceeded error in appmaker

I'm currently validating a date box widget to prevent filing after a 30 days grace period. The date validation was working but after the alert prompted it wasn't going down(I was stock in here even after a couple of clicks). Also the date box is not going null.
function checkDateValidate(widget) {
var form = app.pages.Newitem.descendants;
var otdate = form.otDateBox.value;
var date = new Date();
var pastdate = date.setDate(date.getDate() - 31);
if(otdate <= pastdate) {
alert('Date exceeds within 30 days grace period is invalid.');
form.otDateBox.value = null;
}
}
I expected to clear the date box widget.
This error sometimes happens because there is an infinite loop going on and this is your case. It is very important that you understand the difference between the onValueChange event handler and the onValueEdit event handler.
The onValueChange:
This script will run on the client whenever the value property of this widget changes. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue.
The onValueEdit:
This script will run on the client whenever the value of this widget is edited by the user. The widget can be referenced using parameter widget and the new value of the widget is stored in newValue. Unlike onValueChange(), this runs only when a user changes the value of the widget; it won't run in response to bindings or when the value is set programmatically.
Why is this happening?
Since your logic is set on the onValueChange event handler, this will be triggered everytime the dateBox widget value is changed, even programmatically; Hence, form.otDateBox.value = null; is triggering the logic over and over again. The reason why it is being triggered over and over again is due to your comparison logic:
if(otdate <= pastdate)
Here, the value of otdate has become null wich when converted to number Number(null) the value is 0(zero). The value of pastdate is obviously a number greater than zero, eg 1555413900712. So obviously, zero is less than or equal to 1555413900712 and that is why you are triggering an infinite loop.
So, in summary, there is only one way to fix this. Set the logic inside the onValueEdit event handler instead of the onValueChange.

how to make an object visible again in game maker

Fist of all, I'm really sorry for my bad English and I pretty new to game maker .
I have 2 object in the game : obj_apple and obj_door( I unchecked visible box)
my question is
how can I make an obj_door visible in the room when all the obj_apple are destroyed?
Object obj_door, Step event, place code (Add event -> Step -> Step -> tab Control -> section Code, first icon (Execute code)):
if !instance_exists(obj_apple) visible = true;
Another option, so you aren't making a check in every step event, is to put the check for the number of obj_apple in the destroy event of obj_apple.
For example, in the destroy event of obj_apple you would have:
if (instance_number(object_index) == 0) {
with (obj_door) {
visible = true;
}
}

How to Get row by key value or visible index in ASPxGridView then change column value?

Hi
In ASPxGridView, is there a way to get a row by its VisibleIndex or KeyValue so that I can change any column value in it?, I mean something like this:
var row = myGrid.SelectRowByKeyValue(myKeyValue);
OR:
var row = myGrid.SelectRowByVisibleIndex(myKeyValue);
row["Column1"] = true;
Edit:
What I'm tring to do is that every time I hit the button I want to check one specific row (I'm using ajax to not reload all the page);
Thanks
This can be done using the ASPxGridView.GetRow() method. NOTE, that changing the value in the DataRow is not enough. If you want these changes to be preserved, save them to the DB.
Since you are using unbound columns, you should handle the CustomUnboundColumnData event and provide modified data for this row within this event handler. The common approach is described in the Providing Data for Unbound Columns topic. If this does not help, please describe in greater details.
UPDATE
Your approach is incorrect. The ASPxGridView does not provide a method to set a text of a certain cell (TD). Instead, you should force the grid to raise the CustomUnboundColumnData event. This can be done using the ASPxGridView's DataBind method. In this event handler, you should determine the KeyField value of the processed row, compare it with the keyField value of the row where the button was clicked and return the required value. This is how I would implement this feature...
I solved it by using this code:
for (int i = 0; i < myGridView.VisibleRowCount; i++)
{
if ( [My condition] )
{
(
(CheckBox)myGridView
.FindRowCellTemplateControl(i,
myGridView.Columns["MyColumnName"] as GridViewDataColumn,
"My_Unbound_Control_Name"
)
).Checked = true;
}
}
I's may not be the right way to do it but I couldn't solve it another way.

Get selectedIndex from a dropdown list on submit

This is my first web page ever and I can't seem to find the correct way to get the selected index from a dropdown list. I don't need the selected index until the user presses the submit button. I've been testing everything I've found on the subject, but nothing is working.
I don't want the drop-down box to reset when the selection is made, which is what happens if I use postback=true or any selected index changed events. And, I still get an index of 0.
When I test, the selected index is always zero.
This runs on page load:
ddlBudgetLineItem.DataSource = budget.BudgetLineItems;
ddlBudgetLineItem.DataTextField = "Name";
ddlBudgetLineItem.DataValueField = "BudgetLineItemID";
ddlBudgetLineItem.DataBind();
This is the drop-down list:
<asp:DropDownList ID="ddlBudgetLineItem" runat="server">
</asp:DropDownList>
Here is the code that needs the index:
protected void submitPayment()
{
string amountValue = txtAmount.Text.ToString();
float amount = float.Parse(amountValue);
Payment payment = new Payment()
{
Amount = amount,
Payee = txtPayee.Text,
BudgetLineItem = budget.BudgetLineItems[ddlBudgetLineItem.SelectedIndex],
Memo = txtMemo.Text,
PaymentDate = DateTime.Parse(txtPaymentDate.Text),
ExtraUserInfo = info
};
provider.AddPayment(payment);
}
Any assistance is appreciated.
it seems to be a life cycle issue, this is happening because everytime (on a postback or not) the page is loaded, your dropdown is rebuilt (caused by ddlBudgetLineItem.DataBind()), concluding that on a postback your ddl will get index=0 forever.
how can you solve this:
1: Override the page databind method and put your code before call base.databind(); (inside the method)
2: on your load event you just have to call databind (if not is postback), it prevent to rebuild your object states everytime your page is loaded.(cause of your lost information).
3: take a look on a page lifecycle it will help you to prevent future issues like that.

How to get a handle to a dynamic imagebutton in an ajax panel postback

I write an imagebutton to a table cell in a new row when a user selects an item in a list:
ImageButton imgbtnRemove = new ImageButton();
imgbtnRemove.ID = "uxStandardLetterDeleteImage_" + items.letterName;
imgbtnRemove.CommandName = "uxStandardLetterDeleteImage_" + items.letterName;
imgbtnRemove.ImageUrl = items.remove;
imgStatus.AlternateText = "Remove";
tRow.Cells[3].Controls.Add(imgbtnRemove);
When the new imagebutton is clicked, I can't seem to get a handle to it. I see it in Page_PreRender event, where I also reload the table on each postback.
string returnData = Request.Form.ToString();
but iterating through the form controls images:
if (c is System.Web.UI.WebControls.Button ||
c is System.Web.UI.WebControls.ImageButton)
does not find it. I can find it if I manually put in a:
imgbtnRemove.Click += new System.Web.UI.ImageClickEventHandler(this.ButtonClick);
in the Page_Load and then grab it in the click event:
switch (((System.Web.UI.WebControls.ImageButton)sender).CommandName)
...
but because there are new rows being added and deleted, this gets rather ugly programmatically. I'm thinking there must be an elegant solution to dynamic imagebutton creation and retrieval on the fly from server side code. I've done a lot of digging but this one is stumping me.
Thanks in advance...
If you're creating dynamic controls during the event handling phase of the Page lifecycle (for example, in the item selected event), then the control will be gone on the next postback.
In order for dynamic controls to be registered with ViewState, they have to be created in the Init phase of the event lifecycle.
Also, you say you're iterating through the Form's controls... when you are adding the imagebutton to the table's cells. Are you recursively descending the control heirarchy to look for the imagebutton?

Resources