winform中:
dateGridView 绑定数据后,
1.每行数据库向上或向下滚动显示?
2.根据里面某个字段,可以每行的颜色可以控制?
可不可以实现?

解决方案 »

  1.   

    滚动显示:
    for (int i = 0; i < grdView.Rows.Count; i++)
                    {
                        grdView.FirstDisplayedScrollingRowIndex = i;
                    }控制颜色:
    DataGridViewRow row = this.grdView.Rows[selectIndex];
                        if ((bool)row.Cells["colReviewed"].Value)
                        {
                            row.DefaultCellStyle.BackColor = Color.LightGreen;
                        }
                        else
                        {
                            row.DefaultCellStyle.BackColor = Color.White;
                        }                    if (row.Cells["colIsMask"].Value.ToString().ToLower() == "true")
                        {
                            row.Cells["colIsMask"].Style.BackColor = Color.Red;
                        }
                        else
                        {
                            row.Cells["colIsMask"].Style.BackColor = isReviewEnd ? Color.LightGreen : Color.White;
                        }
      

  2.   

    这两个看看,对你有帮助的
    http://hi.baidu.com/wowo2jia/blog/item/7cbe0d7c577014ec0ad187a7.html
    http://blog.csdn.net/chyocean/article/details/2062684
      

  3.   


    private void dataGridView1_RowsAdded(object sender, DataGridViewRowsAddedEventArgs e)
            {
                string title = "";
                if (e.RowIndex >= 0)
                {
                    try
                    {
                        title = dataGridView1.Rows[e.RowIndex].Cells["Title"].Value.ToString();
                    }
                    catch { title = ""; }
                }
                if (title == "002")
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
            }
      

  4.   

    对于第一点,lz可以看看6楼提供的方法,很好!
    对于第二点,再来一个方法:private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
    {
        try
        {
            if (e.ColumnIndex == 1)        //控制要格式化的列
            {
                bool b = Convert.ToBoolean(dataGridView1.CurrentRow.Cells[e.ColumnIndex].Value);
                if(b)
                    dataGridView1.Rows[e.RowIndex].DefaultCellStyle.BackColor = Color.LightGray;
                    }
                }
                catch (System.Exception ex)
                {
                    
                }
            }