This is a migrated thread and some comments may be shown as answers.

How to merge 2 columns in radgridview

1 Answer 158 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Vishal
Top achievements
Rank 1
Vishal asked on 22 Oct 2012, 02:11 PM
Hi,

How to merge 2 columns and have a single header Text for the merged columns

Ex:

current o/p
Col1   Col2  col3  col4
r1c1   r1c2  r1c3  r1c4
r2c1  r2c2  r2c3   r2c4
r3c1  r3c2  r3c3   r3c4

current o/p
Col1  MergedCol  col4
r1c1    r1c2r1c3      r1c4
r2c1    r2c2r2c3      r2c4
r3c1    r3c2r3c3      r3c4

1 Answer, 1 is accepted

Sort by
0
Anton
Telerik team
answered on 23 Oct 2012, 01:37 PM
Hi Vishal,

Thank you for writing.

The described scenario is not supported out of the box. However one way to achieve the desired functionality is to:
1.Create some wrapper that wrap your data source.
2.Make your custom logic in the wrapper.

For example:
public partial class Form1 : Form
{
    public Form1()
    {
        InitializeComponent();
    }
 
    private void Form1_Load(object sender, EventArgs e)
    {
        BindingList<Element> datasource = new BindingList<Element>()
        {
            new Element(1,"mike","Toshiba"),
            new Element(2,"peter","Dell"),
        };
 
        this.radGridView1.DataSource = WrapDataSource(datasource); ;
    }
 
    private object WrapDataSource(BindingList<Element> datasource)
    {
        BindingList<NewElement> newDataSource = new BindingList<NewElement>();
        foreach (Element item in datasource)
        {
            newDataSource.Add(new NewElement(item.Id,item.Name+item.Item));
        }
        return newDataSource;
    }
}
 
public class Element
{
    public int Id { get; set; }
    public string Name { get; set; }
    public string Item { get; set; }
 
    public Element(int id, string name, string item)
    {
        this.Id = id;
        this.Name = name;
        this.Item = item;
    }
}
public class NewElement
{
    public int Id { get; set; }
    public string MergeText { get; set; }
 
    public NewElement(int id, string newText)
    {
        this.Id = id;
        this.MergeText = newText;
    }
}

I hope this information helps. If you have further questions, feel free to write back

Greetings,
Anton
the Telerik team
You’ve been asking for it and now it’s time for us to deliver. RadControls for WinForms Q3 2012 release is just around the corner. Sign up for a free webinar to see first all the latest enhancements.
Tags
GridView
Asked by
Vishal
Top achievements
Rank 1
Answers by
Anton
Telerik team
Share this question
or