Selecting multiple options from a ListBox in GridView causes an error

Note: This applies to forms created in a previous version of WorkflowGen and upgraded to version 6.0.

Selecting multiple options from a ListBox inside a GridView and then editing causes an error with the message “X has a SelectedValue which is invalid because it does not exist in the list of items” and the exception System.ArgumentOutOfRangeException. This is because as of WorkflowGen 6.0, a ListBox inside a GridView can save several selected values, whereas previously it only saved the first selected value.

To prevent this:

If the form was created using the Form designer in an earlier version of WorkflowGen, open the process form in the Form designer, then save it to update it.

If the form was not created using the Form designer, remove the SelectedValue property of the ListBox inside the GridView. WorkflowGen will manually bind the ListBox to the selected values in the background.

In either case, to mimic the behaviour of WorkflowGen 5.7.2 and earlier, add the following code to the .NET script, where REQUEST_GRIDVIEW1 is the affected gridview and IndexOfCellWithListBoxis the zero-based index of the cell that contains a ListBox:

protected void Page_LoadComplete(object sender, EventArgs e)

{

 foreach(GridViewRow row in **REQUEST_GRIDVIEW1**.Rows)

 {

 Control ctrl = row.Cells[**IndexOfCellWithListBox**].Controls[0];

 if(ctrl is ListBox)

 {

 ((ListBox)ctrl).SelectionMode = ListSelectionMode.Single;

 }

 }

}