Strategies for Unlocking Knowledge Management in Microsoft 365 in the Copilot...
Fixing an annoying GridView problem
1. Solving a frustrating GridView shortcoming By Roger Pence How to solve a frustrating GridView problem… while learning a cool OO technique: decorator classes.
2.
3.
4.
5. Fixing the problem… the first pass BegSr gvCust_RowCreated Access(*Private) + Event(*This.gvCust.RowCreated) DclSrParm sender Type(*Object) DclSrParm e Type(GridViewRowEventArgs) DclFld lb Type( LinkButton ) DclFld RowCounter Type( *Integer4 ) Static( *Yes ) If ( e.Row.RowType = DataControlRowType.DataRow ) ForEach tc Type( TableCell ) Collection( e.Row.Cells ) If ( tc.Controls.Count > 0 ) lb = tc.Controls[ 0 ] *As LinkButton If ( lb <> *Nothing ) lb.CommandArgument = RowCounter EndIf EndIf EndFor RowCounter += 1 EndIf EndSr In the RowCreated event, set each LinkButton’s CommandArgument property to the ordinal row number
6. Fixing the problem… the first pass BegSr gvCust_RowCommand Access(*Private) + Event(*This.gvCust.RowCommand) DclSrParm sender Type(*Object) DclSrParm e Type( GridViewCommandEventArgs ) // Column clicked available in e.CommandName. lblColumnSelected.Text = e.CommandName // Row clicked available in e.CommandArgument. lblRowSelected.Text = e.CommandArgument EndSr This makes the CommandButton’s CommandName available in e’s CommandName property and the row clicked in e’s CommandArgument property.