I''m having a couple of issue involving deleting rows from the underlying data for a GDBG. My GDBG is bound to a custom collection, CustomerIncomes, which contains CustomerIncome objects.
1) If the CurrentCell is on the bottom row of the grid and I remove that CustomerIncome object from CustomerIncomes (and then do grid.RefreshRange(grid.ViewLayout.VisibleCellsRange, True)), the CurrentCell.RowIndex is a row off the bottom of the grid now. How can I tell if CurrentCell.RowIndex is a valid row or not?
2) If I have three rows in the GDBG ("A", "B", and "C") with the CurrentCell in the middle row ("B"), and I remove that CustomerIncome object from CustomerIncomes and do a RefreshRange(...), the grid ends up showing rows "A" and "C" in the first two rows, and a partial "ghost" image of row "C" in a third row (see attached screen shot). Below is my code for my DeleteData() method.
Private Sub DeleteData()
With dtgEmployerInfo
If m_Incomes.Count > 0 AndAlso dtgEmployerInfo.CurrentCell.RowIndex > -1 Then
Dim Index As Integer = .CurrentCell.RowIndex
Dim Msg As String = String.Format( _
"Are you sure you want to delete the following Income?{0}{0}" & _
" Income Source: {1}{0}" & _
" Employer Name: {2}{0}" & _
" Work Phone: {3}{0}" & _
" Extension: {4}{0}" & _
" Income Range: {5}", _
ControlChars.CrLf, _
.Item(Index, .Binder.NameToColIndex(INCOME_TYPE_COLUMN)).CellValue.ToString, _
.Item(Index, .Binder.NameToColIndex(EMPLOYER_NAME_COLUMN)).CellValue.ToString, _
.Item(Index, .Binder.NameToColIndex(WORK_PHONE_COLUMN)).CellValue.ToString, _
.Item(Index, .Binder.NameToColIndex(EXTENSION_COLUMN)).CellValue.ToString, _
.Item(Index, .Binder.NameToColIndex(INCOME_RANGE_COLUMN)).CellValue.ToString)
Dim Result As MsgBoxResult = MsgBox(Msg, MsgBoxStyle.YesNo, "Delete Income?")
If Result = MsgBoxResult.Yes Then
Dim Position As Integer = .Binder.RowIndexToPosition(Index)
If Position < 0 Or Position > m_Incomes.Count - 1 Then
Throw New ApplicationException("Invalid Income Index. Cannot delete selected Income.")
End If
m_Incomes.Remove(m_Incomes(Position))
If m_Incomes.Count > 0 Then
.CurrentCell.MoveTo(1, 1)
.CurrentCell.ScrollInView()
End If
.RefreshRange(.ViewLayout.VisibleCellsRange, True)
DisplayData()
End If
End If
End With
End Sub
-----
Lee Perkins