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

Group by Lookup Column showing wrong value

4 Answers 152 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Erkut
Top achievements
Rank 1
Erkut asked on 07 Oct 2010, 03:00 PM
Hi Telerik Team,

I have a gridview which displays a bunch of tasks for users. I've got some lookup columns. One of them is the Owner of the task. There is a binding source to get userlist. The lookup column's display member is the name and value member is guid of the user which works perfectly fine until gw is grouped by this column. When you group by it shows the guid instead of the name of the user. So i see something like 284C8520-9687-4460-B11B-85A3A65E0771 instead of System Administrator and this behavior is the same for every lookup column with guids. Can anyone help me out on this?
Thanks in advance.

4 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Oct 2010, 03:15 PM
Hello Erkut,

In order to be able to format the group header you should use GroupSummaryEvaluate event to format the displayed text according to your particular needs. Please find out how to do that in the product documentation.

Hope this helps, if you have any other questions or comments, please let me know,

Best Regards,
Emanuel Varga
0
Erkut
Top achievements
Rank 1
answered on 07 Oct 2010, 04:09 PM
Thank you for your fast response Emanuel. However this used to work before the last update. My problem is gridview is displaying the value member instead of the display member. And as i said previous builds had different behavior. The link in your post is broken however I found it after a little googling. I tried every property in this event but could not get the value member.
Thanks again.
0
Emanuel Varga
Top achievements
Rank 1
answered on 07 Oct 2010, 04:34 PM
Hello again Erkut,

I know it should do this, switch the ValueMember with the DisplayMember, as a bug in this version, but i cannot get it to do that in my code, i will attach my code here and please let me know what i have to change, and after that i will help you fix this.

using System;
    using System.Collections.Generic;
    using System.ComponentModel;
    using System.Windows.Forms;
    using Telerik.WinControls.UI;
 
    public partial class Form1 : Form
    {
        private static List<Guid> guids = new List<Guid>();
 
        public static List<Guid> Guids
        {
            get
            {
                return Form1.guids;
            }
            set
            {
                Form1.guids = value;
            }
        }
 
        public Form1()
        {
            InitializeComponent();
 
            this.Size = new System.Drawing.Size(600, 400);
 
            for (int i = 0; i < 100; i++)
            {
                guids.Add(Guid.NewGuid());
            }
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            radGridView1.Dock = DockStyle.Fill;
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.DataBindingComplete += new GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
            this.radGridView1.DataSource = new ProductsCollection();
            radGridView1.GroupSummaryEvaluate += new GroupSummaryEvaluateEventHandler(radGridView1_GroupSummaryEvaluate);
        }
 
        void radGridView1_GroupSummaryEvaluate(object sender, GroupSummaryEvaluationEventArgs e)
        {
        }
 
        void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        {
            radGridView1.Columns["DistributorId"].IsVisible = false;
 
            var column = new GridViewComboBoxColumn("Distribuitor", "Distribuitor");
            column.DataSource = new DistributorsCollection();
            column.ValueMember = "Id";
            column.FieldName = "DistributorId";
            column.DisplayMember = "Name";
            this.radGridView1.Columns.Add(column);
 
            this.radGridView1.BestFitColumns();
        }
    }
 
    #region Helpers
 
    public class Product
    {
        public Guid Id
        {
            get;
            set;
        }
 
        public string Name
        {
            get;
            set;
        }
 
        public Guid DistributorId
        {
            get;
            set;
        }
 
        public Product(Guid id, string name, Guid distribuitorId)
        {
            this.Id = id;
            this.Name = name;
            this.DistributorId = distribuitorId;
        }
    }
 
    public class Distributor
    {
        public Guid Id
        {
            get;
            set;
        }
 
        public string Name
        {
            get;
            set;
        }
 
        public Distributor(Guid id, string name)
        {
            this.Id = id;
            this.Name = name;
        }
    }
 
    public class ProductsCollection : BindingList<Product>
    {
        public ProductsCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Product(Form1.Guids[i], "product" + (i + 1), Form1.Guids[i + 5]));
            }
        }
    }
 
    public class DistributorsCollection : BindingList<Distributor>
    {
        public DistributorsCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Distributor(Form1.Guids[i + 5], "distributor" + (i + 1)));
            }
        }
    }
 
    #endregion Helpers

Best Regards,
Emanuel Varga
0
Erkut
Top achievements
Rank 1
answered on 08 Oct 2010, 09:38 AM
Thank you Emanuel for your code and effort. This is pretty much what i was doing but instead of declaring lists in code behind I am using bindingsources. Interestingly enough removing the gridview and creating it again solved the issue which doesn't make any sense to me. Anyways thanks again Emanuel your help is appreciated.
Erkut.
Tags
GridView
Asked by
Erkut
Top achievements
Rank 1
Answers by
Emanuel Varga
Top achievements
Rank 1
Erkut
Top achievements
Rank 1
Share this question
or