.Net: DataGridView Responding to IBinding.ListChanged but not CellValueChanged Event Handler

有些话、适合烂在心里 提交于 2020-01-04 06:15:01

问题


I have a custom IBinding List which raises the ListChanged event. I would like to recolor the Datagridview row after the ListChanged event.

The Datagridview is responding to ListChanged event and changes the cell value but the CellValueChanged event is never fired.

What Datagridview event reflects the ListChanged event?

Class CustomList : IBinding

Public Sub UpdateList(Byval index as Integer)
     List(index).Active = true
     RaiseEvent ListChanged(Me, _
        New System.ComponentModel.ListChangedEventArgs _
        (System.ComponentModel.ListChangedType.ItemChanged, index))
End Sub

Class CustomDataGridView : DataGridView

Private Sub Grid_CellValueChanged(ByVal sender As Object, _
            ByVal e As System.Windows.Forms.DataGridViewCellEventArgs) _
            Handles Me.CellValueChanged
     ColorRow(Rows(e.RowIndex)) ''//NeverFires
End Sub

Class : Form

Private Sub Form_Load(ByVal sender As Object, ByVal e As System.EventArgs) _
                Handles Me.Load

        Dim customList As New CustomList()
        customList.add(new CustomItem())
        dgv.DataSource = customList
        customList.UpdateList(0) ''//DatagridView updates but no event is raised

End Sub

Update:

CellValueChanged event only fires when a new value is pushed from the DGV to the DT. Not other way round.

– Vivek Apr 5 at 18:52


回答1:


Changing the cells background color should be done in the RowPrePaint-Event, this will be fired if the row is repainted, after the value change.



来源:https://stackoverflow.com/questions/3517310/net-datagridview-responding-to-ibinding-listchanged-but-not-cellvaluechanged-e

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!