Datagridview - Failed to get the value of a cell after to click on the titles to sort.

Datagridview - Failed to get the value of a cell after to click on the titles to sort.

Error of index.

How can I solve this problem?

 

code:

method-id dataGridView1_CellContentClick final private.
01 ws-protocolo     pic x(11).

procedure division using by value sender as object e as type System.Windows.Forms.DataGridViewCellEventArgs.

set ws-protocolo to dataGridView1::Rows::Item(e::RowIndex)::Cells["Protocolo"]::Value::ToString()

end-code


  • Verified Answer

    If the click occurs in the Column Header the RowIndex will be -1.

    Try checking this before executing your statement:

              if e::RowIndex > -1

                 set ws-protocolo to dataGridView1::Rows::Item(e::RowIndex)::Cells["Protocolo"]::Value::ToString()

              end-if