VB.Net(Winforms)で次のコードを使用して、DataGridView
をループし、不要な行を非表示にしています。呼び出しのターゲットによってVB.Net例外がスローされました
An unhandled exception of type 'System.Reflection.TargetInvocationException' occurred in mscorlib.dll
Additional information: Exception has been thrown by the target of an invocation.
私はこれがある理由を理解するために私は考えることができるすべてのものをしようとしてきた:デバッガはIF
文の最初の行になると、私は次のエラーを取得する
Private Sub Overview_Workstream_Sort_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Overview_Workstream_Sort.SelectedIndexChanged
For Each row In Incident_Persons_List.Rows
If Incident_Persons_List.Rows(CInt(row)).Cells(7).Value.ToString.Contains(Overview_Workstream_Sort.SelectedItem.ToString) Then
Debug.Print("User found in workstream")
Incident_Persons_List.Rows(CInt(row)).Visible = True
Else
Incident_Persons_List.Rows(CInt(row)).Visible = False
End If
Next
End Sub
。私は間違いを見てきましたが、この例外がスローされたときには誰もが全く異なる問題を抱えているようです。
私はどのように比較をしているのですか?
UPDATE 1
- Iは実際の例外がスローされることを明らかにしたように、私は
Try/Catch
Cint
命令 - を除去した
For Each
を除去しFor i = 0 to Incident_Persons_list.Rows.Count
- に置き換えたある:
Row associated with the currency manager's position cannot be made invisible.
すべてが今、以下のコードで正常に動作している2
UPDATE:助けを
がPrivate Sub Overview_Workstream_Sort_SelectedIndexChanged(sender As Object, e As EventArgs) Handles Overview_Workstream_Sort.SelectedIndexChanged
Try
For i = 0 To Incident_Persons_List.Rows.Count - 1
If Incident_Persons_List.Rows(i).Cells(7).Value.ToString.Contains(Overview_Workstream_Sort.SelectedItem.ToString) Then
Debug.Print("User found in workstream")
Incident_Persons_List.Rows(i).Visible = True
Else
'Your code that will throw the Exception
Incident_Persons_List.CurrentCell = Nothing
Incident_Persons_List.Rows(i).Visible = False
End If
Next
Catch ex As TargetInvocationException
'We only catch this one, so you can catch other exception later on
'We get the inner exception because ex is not helpfull
Dim iEX = ex.InnerException
Debug.Print(iEX.Message)
Catch ex As Exception
Debug.Print(ex.Message)
End Try
End Sub
ありがとう!
**完全な例外の詳細を表示すると、InnerExceptionは何がうまくいかないかを知る上で重要です。何の内部例外はありません –
が、それは私が – SilverShotBee
ラップのtry/catch構造のコードブロックを直面してる問題だし、InnerExcpetion –