0
此刻我有一個DataGridView(bindet到一個DataTable)和一些標籤。如果DataGridView的事件SelectionChanged發生,標籤應該填充所選行的信息 - >沒有問題。但是,如果我排序DataGridView並單擊一行,標籤中的信息是錯誤的。DataGridView綁定到DataTable - 現在排序DataGridView
事件:
Private Sub DGVMain_SelectionChanged(ByVal sender As System.Object, ByVal e As System.EventArgs) Handles DGVMain.SelectionChanged
If DGVMain.SelectedRows.Count > 0 AndAlso Not Me.DGVMain Is Nothing Then
Dim index As Integer = DGVMain.SelectedRows(0).Index
Dim row As ResultSet.ResultsRow = CType(DGVMain.DataSource, ResultSet.ResultsDataTable).Rows(index)
SetDetails(row)
End If
End Sub
設置標籤的細節:
Private Sub SetDetails(ByVal row As ResultSet.ResultsRow)
Dim rounding As Integer = 0
If row.AssayDisplayResultFormat.Contains(":") Then
rounding = Integer.Parse(row.AssayDisplayResultFormat.Split(":")(1))
End If
LBResultValue.Text = Round(row.ResultResultValue * row.AssayDisplayResultFactor, rounding) & " " & row.AssayDisplayResultUnit
LBAssayNameValue.Text = row.AssayDisplayShortName & " (" & row.AssayOID & ")"
LBSampleIdValue.Text = row.ResourceName
LBCreationDateValue.Text = row.ResourceCreated
LBFlagsValue.Text = ""
LBRawValue.Text = Round(row.ResultRawValue, rounding) & " " & row.AssayDisplayResultUnit
End Sub