在form1:private void Flex_MouseDoubleClick(object sender, MouseEventArgs e)
        {
            if (e.Button == System.Windows.Forms.MouseButtons.Left && Flex.Col == 3 )
            {
                Form2 form2 = new Form2();                List<KeyValuePair<string, int>> listIdAndName = new List<KeyValuePair<string, int>>();
                for (int intRow = Flex.Rows.Fixed; intRow < Flex.Rows.Count; intRow++)
                {
                    if (Flex[intRow, 3] != null)
                    {
                        int intMark = (int)Flex[intRow, 3];
                        if (intMark == 0)
                        {
                            string strName = (string)Flex[intRow, 2];
                            listIdAndName.Add(new KeyValuePair<string, int>(strName, intMark));
                        }
                    }
                }
                form2.SetData(listIdAndName);
                form2.ShowDialog();
            }
        }在form2:  public void SetData(List<KeyValuePair<string, int>> listIdAndName)
        {
            Grid1.Rows.Count = Grid1.Rows.Fixed + listIdAndName.Count;
            for (int i = 0; i < listIdAndName.Count; i++)
            {
                Grid1[i + Grid1.Rows.Fixed, 2] = listIdAndName[i].Key;
                Grid1[i + Grid1.Rows.Fixed, 3] = listIdAndName[i].Value;
            }
        }现在只能显示筛选后的name 与  列,如何显示ID列呢?
如何在form2的column[1]显示筛选后form1里的ID

解决方案 »

  1.   

                Dictionary<string, KeyValuePair<string, int>> dic = new Dictionary<string, KeyValuePair<string, int>>();
                dic.Add("id1234", new KeyValuePair<string, int>("cate", 23));
                foreach (KeyValuePair<string, KeyValuePair<string, int>> key in dic)
                {
                    Console.WriteLine(string.Concat("ID",key.Key,"NAME",key.Value.Key,"AGE",key.Value.Value));
                }
      

  2.   


    如果要引用更多的列呢?
    比如:第1~7列分别是xh,bn,xm,age,sex,ww,qq,要根据第8列的bb的内容进行筛选,在form2显示筛选结果(显示第1~7列)的内容,该怎么用呢?
      

  3.   

    不要用  KeyValuePair<string, int> 存储你可以自己定义一个固定的结构 也可以用集合来存区别就是一个是强类型  另一个不是 
      

  4.   

    你的Grid1.Rows里每行的内容是固定的,你是知道的。你可以把行里所有Cell的内容,定义成一个类  类的属性就是全部的Cell 多少个Cell就多少个属性这样的好处是 不同的属性 类型可以不一样  eg: int ,string , etc ..你可以.出来。 还一个办法是定义k/v 键值对,这个的缺点是  如果是泛型的话,那么全部Cell都需要定义成同一个类型如果非泛型  你还是要知道具体类型然后进行类型转换。
      

  5.   

    那你就写一个类,把类放到数组中,传过去,或者你直接把Flex.Rows传过去在form2中处理。我写的那个是在你基础上实现的功能,前两种方法更靠谱。
      

  6.   

    我这个c#新手,确实有些不懂,Tsapi,Sandy045两位老师,能否写个具体的代码例子,Form1: 第1~7列 id xh bh xm age sex salary 根据第8列 bb 进行筛选显示在Form2谢谢如何定义类啊
      

  7.   

    这么说把, Form1中的表格 是如何显示的呢? 它的数据源是什么呢如果是DataTable 的话,那你用 DataTable.Copy 方法就可以复制一个出来然后根据你的筛选条件 进行删除 之后把这个复制出来的传递到Form2中显示即可
      

  8.   

    http://www.c-sharpcorner.com/Forums/Thread/152674/how-to-show-the-filter-result-in-popuped-form2.aspx可否帮我修改一下呢?