首页 新闻 会员 周边 捐助

改变DatagridView中的元素,并是该行反显出来

0
悬赏园豆:30 [待解决问题]
int RowNum = this.doubleBufferListView1.Rows.Count;//总行数
int ColumnNum = this.doubleBufferListView1.Rows[1].Cells.Count;//得到总列数
for (int i = 0; i < RowNum; i++)
{
for (int j = 0; j < ColumnNum; j++)
{
if (doubleBufferListView1.Rows[i].Cells[j].Value.ToString() == "国债")
{
MessageBox.Show(i.ToString());
DataGridViewCellStyle style = new DataGridViewCellStyle();
style.BackColor = Color.Red;
this.doubleBufferListView1.Rows[i].DefaultCellStyle = style;


}
}
}
~@@~的主页 ~@@~ | 初学一级 | 园豆:35
提问于:2012-05-07 17:57
< >
分享
所有回答(1)
0

在datagridview中的这个事件中写:

private void dataGridView1_CellFormatting(object sender, DataGridViewCellFormattingEventArgs e)
{
    // If the column is the Artist column, check the
    // value.
    if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Artist")
    {
        if (e.Value != null)
        {
            // Check for the string "pink" in the cell.
            string stringValue = (string)e.Value;
            stringValue = stringValue.ToLower();
            if ((stringValue.IndexOf("pink") > -1))
            {
                e.CellStyle.BackColor = Color.Pink;
            }

        }
    }
    else if (this.dataGridView1.Columns[e.ColumnIndex].Name == "Release Date")
    {
        ShortFormDateFormat(e);
    }
}

直接给e.Value赋值,就可以改变原来的值。

http://www.telerik.com/help/winforms/gridview-cells-formatting-cells.html

悟行 | 园豆:12559 (专家六级) | 2012-05-07 19:58
清除回答草稿
   您需要登录以后才能回答,未注册用户请先注册