I've got a list in a datagridview with two columns. The first column has a list of items, and the second has red X's. When the user clicks the red x in the second column, it will remove that row. For some reason, whenever I delete a row, one of my red x's turns black. I've tried stepping through it and even adding some code after the row is deleted to turn all of the x's red, but I cannot figure out why this is happening or stop it from happening.
Here is the code that adds rows to the datagridview.
And here is the code that deletes rows.
Here is the code that adds rows to the datagridview.
Code:
Private Sub AddItem_Click(sender As Object, e As System.EventArgs) Handles AddItem.Click
TableofContents.Rows.Add()
With TableofContents.Rows(TableofContents.Rows.Count - 1)
.Cells(0).Value = InputBox(Prompt:="Please enter an item name.", Title:="Item Name")
.Cells(1).Value = "x"
.Cells(1).Style.ForeColor = Color.Red
.Cells(1).Style.Alignment = DataGridViewContentAlignment.BottomCenter
End With
End SubCode:
Private Sub TableofContents_CellClick(sender As Object, e As System.Windows.Forms.DataGridViewCellEventArgs) Handles TableofContents.CellClick
If e.ColumnIndex = 0 Then
MsgBox("You just selected " & TableofContents.Rows(e.RowIndex).Cells(0).Value & ".")
Else
TableofContents.Rows.RemoveAt(e.RowIndex)
End If
End Sub