سؤال

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