笔记(RemoveAll;DataGridView用linq查询;动态添加控件时闪烁问题)

来源:互联网 发布:java web start 1.4.2 编辑:程序博客网 时间:2024/06/06 00:13

1.RemoveAll

List<Emp> empList = new List<Emp>();List<Emp> empList1 = new List<Emp>();Emp emp = new Emp() { Emp_Id = 1,Emp_Name="a"};Emp emp1 = new Emp() { Emp_Id = 1,Emp_Name="a"};empList.Add(emp);empList1.Add(emp1);int i = empList.RemoveAll(p=>empList1.Contains(p));//i=0,没有移除//这里没有移除是因为bool flag = empList1.Contains(emp)/*flag=fasle,个人理解List<T>,T为引用类型时Contains比较的是地址,虽然emp和emp1属性值一样,但是是不同的对象,不同的地址;值类型比较值,字符串是有值特性的引用类型*/flag = empList1.Contains(emp1) //flag=true

2.DataGridView用linq查询

IEnumerable<DataGridViewRow> emplist = this.dataGridEmp.Rows.Cast<DataGridViewRow>();var query = emplist.Max(s => s.Cells[1].Value);//查询第二列的最大值

3.动态添加控件时闪烁问题
将以下代码加在窗体里

        protected override CreateParams CreateParams        {            get            {                CreateParams cp = base.CreateParams;                cp.ExStyle |= 0x02000000;                return cp;            }        }