winform中datagridview事件RowPrePaint中类似与webform中的gridview的rowdatabound事件

我查了一下,ydsunny(小强)   (   )是web的解决方法,在winform里,DataGridView没有RowDataBound事件,如果在winform里,如下修改: 





private   void   dataGridView1_RowPrePaint(object   sender,   DataGridViewRowPrePaintEventArgs   e) 

                { 

                        if   (e.RowIndex   > =   dataGridView1.Rows.Count   -   1) 

                                return; 

                        DataGridViewRow   dgr   =   dataGridView1.Rows[e.RowIndex]; 

                        try 

                        { 

                                if   (dgr.Cells[ "列名 "].Value.ToString()   ==   "比较值 ") 

                                { 

                                        dgr.DefaultCellStyle.ForeColor   =   设置的颜色; 

                                } 

                        } 

                        catch   (Exception   ex) 

                        { 

                                MessageBox.Show(ex.Message); 

                        } 

                }

你可能感兴趣的:(datagridview)