Мне нужно изменить некоторые данные перед отображением в DataGridView, и я использую событие CellValueChanged.Проблема в том, что e.RowIndex равен -1, когда datagridview заполняется источником данных.
Private Sub dgvList_CellValueChanged(sender As Object, e As DataGridViewCellEventArgs) Handles dgvList.CellValueChanged
' Convert date to Persian if the edited cell has date
If dgvList.Rows(e.RowIndex).Cells.Item(e.ColumnIndex).ValueType.ToString = "" Then
' Do something
End If
End Sub
Я обновляю значения, используя его источник данных.Я изменяю DataTable, и DataGridView обновляется автоматически:
Dim MyRow = dstList.Tables("list").NewRow
MyRow.Item("date_reported") = PersianDateTime.Parse(txtDateReport.Text).ToDateTime
MyRow.Item("description") = txtDescription.Text
MyRow.Item("duration") = txtDuration.Text
MyRow.Item("coworkers") = txtCoworkers.Text
MyRow.Item("progress") = numProgress.Value
MyRow.Item("problems") = txtProblems.Text
MyRow.Item("date_created") = Now.Date
' Add this row to the dataset
dstList.Tables("list").Rows.Add(MyRow)
' Apply changes to database
UpdateList()