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

Groupby expression on Lookup column

3 Answers 114 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Dennis
Top achievements
Rank 2
Dennis asked on 24 Sep 2010, 06:04 PM
All,

I have a gridview control with 3 ComboBoxColumns for lookups.  The columns are Distributor Number, Buyer Number and Vendor Number.  The lookups display the distributor name, buyername and vendor name.  When the user groups by one of these columns such as the distributor, the distributor number shows instead of the distributor name.  Is there a way to display the lookup value distributor name in the Group By expression instead of the column value ?

I am using Visual Studio 2010 and Radcontrols for WindForms Q2 2010 SP1.  Thanks in advance for your assistance.

DS

3 Answers, 1 is accepted

Sort by
0
Emanuel Varga
Top achievements
Rank 1
answered on 25 Sep 2010, 11:43 AM
Hello Denis,

I'm trying to understand what exactly are you looking to do here, and I've prepared a small application that creates 2 ComboBoxColumns (you should change LookupColumns with ComboBoxColumns because they offer the same functionality as the ComboBoxColumns and they might be removed soon) for lookups based on the distributor id, buyer id, please take a look at this and tell me if you are trying to do something else...

public partial class Form1 : Form
    {
        public Form1()
        {
            InitializeComponent();
        }
 
        private void Form1_Load(object sender, EventArgs e)
        {
            this.radGridView1.AutoSizeColumnsMode = GridViewAutoSizeColumnsMode.Fill;
            this.radGridView1.DataBindingComplete += new GridViewBindingCompleteEventHandler(radGridView1_DataBindingComplete);
            this.radGridView1.DataSource = new ProductsCollection();
        }
 
        void radGridView1_DataBindingComplete(object sender, GridViewBindingCompleteEventArgs e)
        {
            radGridView1.Columns["DistributorId"].IsVisible = false;
            radGridView1.Columns["BuyerId"].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);
 
            column = new GridViewComboBoxColumn("Buyer", "Buyer");
            column.DataSource = new BuyersCollection();
            column.ValueMember = "Id";
            column.FieldName = "BuyerId";
            column.DisplayMember = "Name";
            this.radGridView1.Columns.Add(column);
 
            this.radGridView1.BestFitColumns();
        }
    }
 
    #region Helpers
 
    public class Product
    {
        public int Id { get; set; }
 
        public string Name { get; set; }
 
        public int DistributorId { get; set; }
 
        public int BuyerId { get; set; }
 
        public Product(int id, string name, int distribuitorId, int buyerId)
        {
            this.Id = id;
            this.Name = name;
            this.DistributorId = distribuitorId;
            this.BuyerId = buyerId;
        }
    }
 
    public class Distributor
    {
        public int Id { get; set; }
 
        public string Name { get; set; }
 
        public Distributor(int id, string name)
        {
            this.Id = id;
            this.Name = name;
        }
    }
 
    public class Buyer
    {
        public int Id { get; set; }
 
        public string Name { get; set; }
 
        public Buyer(int 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(i, "product" + (i + 1), i + 5, i + 10));
            }
        }
    }
 
    public class DistributorsCollection : BindingList<Distributor>
    {
        public DistributorsCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Distributor(i + 5, "distributor" + (i + 1)));
            }
        }
    }
 
    public class BuyersCollection : BindingList<Buyer>
    {
        public BuyersCollection()
        {
            for (int i = 0; i < 10; i++)
            {
                this.Add(new Buyer(i + 10, "Buyer" + (i + 1)));
            }
        }
    }
 
    #endregion Helpers


Here you can group by any column you want and the names will show in the grid. (I'm using the latest version of Telerik controls here, Q2 SP2 but i don't think there is any difference)

Please do not hesitate to say so if you have any other questions.

Best Regards,
Emanuel Varga
0
Martin Vasilev
Telerik team
answered on 30 Sep 2010, 03:15 PM
Hi Dennis,

Thank you for writing.

You are right that if there is a grouping by combo-box column, the group headers row shows column value and not DisplayMember from the combo-box column. You should use GroupSummaryEvaluate event to format the displayed text according to your particular needs. Please find out how to do that in our product documentation.

Let me know if you have any other questions.

Sincerely yours,
Martin Vasilev
the Telerik team
Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Public Issue Tracking system and vote to affect the priority of the items
0
Dennis
Top achievements
Rank 2
answered on 30 Sep 2010, 03:31 PM
Thanks for your replies.  The GroupSummaryEvaluate was exactly what i was looking for but did not know how to describe it properly. 

As a quick and simple fix, i just added the Distributor name column to the stored procedure i am calling but i would rather have a custom group heading.

Thanks Again,

Dennis
Tags
GridView
Asked by
Dennis
Top achievements
Rank 2
Answers by
Emanuel Varga
Top achievements
Rank 1
Martin Vasilev
Telerik team
Dennis
Top achievements
Rank 2
Share this question
or