.Net:DataGridView响应IBinding.ListChanged而不是CellValueChanged事件处理程序 [英] .Net: DataGridView Responding to IBinding.ListChanged but not CellValueChanged Event Handler

查看:238
本文介绍了.Net:DataGridView响应IBinding.ListChanged而不是CellValueChanged事件处理程序的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我有一个自定义IBinding List,它引发了ListChanged事件。我想在ListChanged事件之后重新着色Datagridview行。



Datagridview响应ListChanged事件并更改单元格值,但是CellValueChanged事件永远不会被触发。



Datagridview事件是否反映了ListChanged事件?



类CustomList:IBinding / p>

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

类CustomDataGridView:DataGridView

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

类:表单

  Private Sub Form_Load(ByVal sender As Object,ByVal e As System.EventArgs)_ 
句柄($)
dgv.DataSource = customList
customList.UpdateList(0) ''// DatagridView更新但没有发生事件

End Sub

更新:


仅当
a将新值从DGV推送到$ b时,CellValueChanged事件才会触发$ b DT。不一样。


- Vivek 4月5日18:52

解决方案

更改单元格背景颜色应该在RowPrePaint-Event中完成,如果该行重新绘制,则在值更改后将触发。


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

解决方案

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.

这篇关于.Net:DataGridView响应IBinding.ListChanged而不是CellValueChanged事件处理程序的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆