当前位置:编程学习 > C#/ASP.NET >>

SuperGrid或者DataGridView如何过滤重复值

我目前学用DotNetBar的SuperGrid,做的窗口真漂亮,但是我以前用PowerBuiler的,有过滤重复值功能

就比如我一条SELECT语句结果是

姓名   年份   工作地点
张三    2001    广州 
张三    2003    深圳 
张三    2007    上海
李四    2005    广州 
张四    2008    深圳 
李四    2009    上海
王五    2013    深圳


我要在SuperGrid显示的效果是

姓名   年份   工作地点
张三    2001    广州 
        2003    深圳 
        2007    上海
李四    2005    广州 
        2008    深圳 
        2009    上海
王五    2013    深圳

应该SuperGrid与DataGridView用法差不多吧,只不过前者有很多特色的功能
--------------------编程问答-------------------- 写1个方法 相同列只保存1个 然后再返回给前端 --------------------编程问答-------------------- 秒沉吗?按道理DataGridView估计是要写代码了
DotNetBar的SuperGridControl应该有属性吧,这么强大的控件,没人用过吗 --------------------编程问答-------------------- 100分了还没人回答么,主要针对DotNetBar的SuperGridControl --------------------编程问答--------------------

using System.Collections.Generic;
namespace GeZhongTest
{   
    /// <summary>   
    /// 泛型去重复比较类    
    /// </summary>    
    class ListComparer:IEqualityComparer<string>    
    {        
        public bool Equals(string a, string b)        
        {            
            if (a == b)            
            {                
                return true;            
            }            
            else            
            {                
                return false;               
            }        
        }        
        public int GetHashCode(string obj)        
        {            
            return 0;        
        }    
    }
}
--------------------编程问答--------------------



static void Main(string[] args)        
{            
List<string> list = new List<string>();            
for (int i = 0; i < 5; i++)            
{                
list.Add("shenme" + i);            
}            
list.Add("shenme2");            
list.Add("shenme3");            
for (int j = 10; j < 15; j++)            
{                
list.Add("ha" + j);           
}            
list.Add("ha12");            
Console.WriteLine("去重之前");            
Console.WriteLine("******************************");            
foreach (string eve in list)            
{                
Console.Write(eve + "\t");            
}            
Console.WriteLine("******************************");                        
Console.WriteLine("去重之后");            
Console.WriteLine("******************************");           
//调用方法去重复            
var resultList = list.Distinct(new ListComparer());             
foreach(var item in resultList)            
{               
Console.Write(item.ToString() + "\t");            
}            
Console.WriteLine("******************************");           
Console.ReadKey();        
}
--------------------编程问答-------------------- 楼上的不是我想要的结果啊 --------------------编程问答-------------------- 除 --------------------编程问答-------------------- 难度再次降低,我把代码贴上,我是碰到相同的就隐藏,但是如何让单元格合并居中,博客园上的RowSpan我没这个属性,不知道他们怎么整的!

using DevComponents.DotNetBar.SuperGrid;
using System.Windows.Forms;
/// <summary>
///GridViewMergeCell 合并GridView 
/// </summary>
public class GridViewMerge
{
    public static void spanRow(SuperGridControl dg, string GroupColumn)
    {
        int i = 0;
        int j = 0;
        int rowSpan;
        string strTemp = "";
        string strTemp2 = "";
        GridElement col;
        GridRow a;

        for (i = 0; i < dg.PrimaryGrid.Rows.Count; i++)
        {
            rowSpan = 1;
            col = dg.PrimaryGrid.Rows[i];
            a = col as GridRow;
            strTemp = a.Cells[GroupColumn].Value.ToString();
            for (j = i + 1; j < dg.PrimaryGrid.Rows.Count; j++)
            {
                col = dg.PrimaryGrid.Rows[j];
                a = col as GridRow;
                strTemp2 = a.Cells[GroupColumn].Value.ToString();

                if (string.Compare(strTemp, strTemp2) == 0)
                {
                    rowSpan += 1;
                    //dg.Items[i].Cells[GroupColumn].RowSpan = rowSpan;
                    //dg.Items[j].Cells[GroupColumn].Visible = false;
                    a.Cells[GroupColumn].Visible = false;  
                }
                else
                {
                    break;
                }
            }
            i = j - 1;
        }
    }
    
}
--------------------编程问答-------------------- 顶一下。赶紧上去。。没人回答了 --------------------编程问答-------------------- 不好意思,好长时间没有上CSDN了,看了一下DotnetBar中可能还不能满足你的需求,它是可以分组,但好像是没有合并行的功能,你这个只是要来展示吗? --------------------编程问答-------------------- 它里面有个ListView,可以实现这个效果,但是要手动的添加 --------------------编程问答--------------------
引用 10 楼 llxaphy1314 的回复:
不好意思,好长时间没有上CSDN了,看了一下DotnetBar中可能还不能满足你的需求,它是可以分组,但好像是没有合并行的功能,你这个只是要来展示吗?

谢谢关注,最好可以录入数据!如果不行,你推荐个办法,或者范例,我去学习下 --------------------编程问答-------------------- Spread有这样的功能,Supergrid就不知道了


 FpSpread1.Sheets(i).SetColumnMerge(0, Model.MergePolicy.Always)
补充:.NET技术 ,  C#
CopyRight © 2012 站长网 编程知识问答 www.zzzyk.com All Rights Reserved
部份技术文章来自网络,