문제

Goal

To differentiate different rows from each other based on a custom class object's properties. For example, if the object's available state is not available the row backcolor should be displayed in yellow. Similarly, if the object's deleted state is set to true, the row backcolor should be red.

Current Situation

I have a DataGridView that has it's DataSource set to a DataView. The DataView's Table is set to a DataTable filled with data by the custom class.

I created a method that sets the back colors correctly (tested and it works fine). However, this method is executed on the DataGridView1.RowsAdded event. For some reason, even if I have 20 rows that are added, it only goes through the event twice for the row index 0 and row index 1.

Problem

I need a DataGridView event that will fire my method every time a row is added or every time the RowFilter on my DataView changes. How can I go about doing this?

도움이 되었습니까?

해결책

The best way to deal with custom row/cell style is to subscribe to the following events:

  1. RowPrePaint
  2. RowPostPaint

They are only raised when the row is displayed.

라이센스 : CC-BY-SA ~와 함께 속성
제휴하지 않습니다 StackOverflow
scroll top