首页 > Windows开发 > 详细

(C#) Format the cell of DataGridView based on the TextBox.Text

时间:2015-03-27 19:51:15      阅读:276      评论:0      收藏:0      [点我收藏+]
private void textBox1_TextChanged(object sender, EventArgs e)
        {
            DataGridViewCellStyle style = new DataGridViewCellStyle();
            style.Font = new Font(dataGridView1.Font.FontFamily, this.Font.Size, FontStyle.Bold);
            style.BackColor = Color.Yellow;//any style as you want;
            foreach (DataGridViewRow row in dataGridView1.Rows)
            {
                foreach (DataGridViewCell cell in row.Cells)
                {
                    if (cell.Value != null && !string.IsNullOrEmpty(this.textBox1.Text) && cell.Value.ToString().Contains(this.textBox1.Text))
                    {
                        cell.Style = style;
                    }
                    else
                        cell.Style = dataGridView1.DefaultCellStyle;
                }
                
            }
        }

 Result:

技术分享

 

(C#) Format the cell of DataGridView based on the TextBox.Text

原文:http://www.cnblogs.com/tony-MSDN/p/4372458.html

(0)
(0)
   
举报
评论 一句话评论(0
关于我们 - 联系我们 - 留言反馈 - 联系我们:wmxa8@hotmail.com
© 2014 bubuko.com 版权所有
打开技术之扣,分享程序人生!