Using powerbuilder write a code find the value in list of values attached to the…
- User
Using powerbuilder write a code find the value in list of values attached to the DataWindow's field as DDDW.
- Assistant
Below is an example of how you might write PowerBuilder code to look up a value in the list of values associated with a DataWindow field that uses a Drop-Down DataWindow (DDDW). In this example, we assume that:
- Your main DataWindow control is called
dw_1. - The DataWindow column that uses a DDDW is named
"status". - The DDDW object (child DataWindow) for
"status"has two columns: a display column (for example,"disp_status") and an underlying data column (for example,"data_status").
The code will retrieve the DDDW object for the
"status"column, search for a specified display value (for example, the display value in the current row ofdw_1), and then fetch the corresponding underlying value.Here’s the sample code:
// Declare variables long li_row, li_index, li_dddw_rows string ls_dispValue, ls_dataValue, ls_criteria DataWindowChild ldddw // 1. Determine the current row in the main DataWindow. li_row = dw_1.GetRow() if li_row <= 0 then MessageBox("Error", "No row selected!") return end if // 2. Retrieve the display value from the main DataWindow's column ("status"). ls_dispValue = dw_1.GetItemString(li_row, "status") // 3. Get the DDDW object for the "status" column. dw_1.GetChild("status", ldddw) if not IsValid(ldddw) then MessageBox("Error", "Drop-Down DataWindow for 'status' could not be retrieved.") return end if // 4. Determine the total number of rows in the DDDW. li_dddw_rows = ldddw.RowCount() // 5. Build a search criteria. Here we assume that in the DDDW object the column that holds the display text is "disp_status". ls_criteria = "disp_status = '" + ls_dispValue + "'" // 6. Use the Find function to search the DDDW object for the row with the specified display value. li_index = ldddw.Find(ls_criteria, 1, li_dddw_rows) // 7. If the value is found, retrieve the underlying value from the DDDW. // Assume that the data value is in the column "data_status". if li_index > 0 then ls_dataValue = ldddw.GetItemString(li_index, "data_status") MessageBox("Found", "Underlying value: " + ls_dataValue) else MessageBox("Not Found", "The display value '" + ls_dispValue + "' was not found in the DDDW.") end ifExplanation
-
Get the Current Row:
We first get the current row indw_1using theGetRow()function. If no row is selected, we exit. -
Retrieve the Display Value:
The display value stored in the"status"column is obtained viaGetItemString. This is the value shown in the main DataWindow. -
Get the Child DataWindow (DDDW):
Using theGetChild()function, we get the DDDW object attached to the"status"column. Always check that the object is valid. -
Search in the DDDW:
A search criteria is built (in this case, we are searching for a matchingdisp_statuswhich holds the display text). TheFind()method is then used to locate the row within the DDDW. -
Retrieve the Underlying Value:
If the search finds a match (i.e.li_index > 0), we retrieve the underlying value usingGetItemStringon the DDDW row and display it.
This example shows a typical method to locate a value within a DDDW in PowerBuilder. You may need to adjust the column names (like
"disp_status"and"data_status") to match the definitions in your DataWindow objects. - Your main DataWindow control is called
Other models, same or similar prompt
Responses were produced in different, uncontrolled contexts (system prompts, settings, prior turns). This is not a benchmark.