Combox with Custom Objects

4 posts, 0 answers
  1. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 26 Feb 2013 Link to this post

    Hello,
    in a grid, I want to show a generic list of objects (type: Cars). No problem. One of the columns should be a ComboBox. In the combobox  the selection should be based on a different class (type: Country). The name of country should be displayed in the grid. In both classes, there is a property ID of type GUID. The ID will be created automatically and have no setter.

    using System;
    using Telerik.WinControls.UI;
    using System.Linq;
     
    namespace Grid_Test
    {
        public partial class frmMitarbeiterlister : Telerik.WinControls.UI.RadRibbonForm
        {
            private TestData.Task taskNewBefore = null;
            private TestData.Task taskNewAfter = null;
     
            public frmMitarbeiterlister()
            {
                InitializeComponent();
                
            }
     
     
            private void GetTestData()
            {
                TestData.TestDataGenerator.GenerateTestData(1000);
                gridMitarbeiterListe.DataSource = TestData.DataAccessLayer.EmployeeList;
                gridMitarbeiterListe.BestFitColumns();
            }
            private void btnTestdatenErstellen_Click(object sender, EventArgs e)
            {
                GetTestData();
            }
     
            private void frmMitarbeiterlister_Load(object sender, EventArgs e)
            {  
                GetTestData();
                GetComboBox();
                 
                
            }
     
            private void GetComboBox()
            {
                GridViewComboBoxColumn cbTask = new GridViewComboBoxColumn();
                cbTask.UniqueName = "TaskNew";
                cbTask.HeaderText = "New Task";
                cbTask.DataSource = TestData.DataAccessLayer.TaskCatalog;
                cbTask.ValueMember = "ID";
                cbTask.DisplayMember = "Description";
                cbTask.FieldName = "TaskNew.ID"; // Name in the employee-class
                 
                gridMitarbeiterListe.MasterTemplate.Columns.Add(cbTask);
     
                // problem: After leaving the row the new value disapear.
            }
        }
    }

    Here is my class model
    using System;
    using System.Collections.Generic;
    using System.Linq;
     
     
    namespace Grid_Test.TestData
    {
        internal static class DataAccessLayer
        {
            internal static  List<Employee> employeeList = new List<Employee>();
            internal static List<Task> taskCatalog = new List<Task>();
     
            public static List<Employee> EmployeeList
            {
                get {
                    if (employeeList == null) { employeeList = new List<Employee>(); }
                    return employeeList;
                }
            }
     
            public static List<Task> TaskCatalog
            {
                get
                {
                    if (taskCatalog == null)
                    { taskCatalog = new List<Task>(); }
                    return taskCatalog;
                }
            }
        }
    }


    internal class Employee
        {
            internal Employee() { }
     
            private Guid id = Guid.NewGuid();
            private string firstname;
            private string lastname;
            private DateTime birthDay;
            private Task taskOld;
            private Task taskNew;
     
            public Guid ID { get { return id; } }
            public string Firstname { get { return firstname; } set { firstname = value; } }
            public string Lastname { get { return lastname; } set { lastname = value; } }
            public DateTime BirthDay { get { return birthDay; } set { birthDay = value; } }
            public Task TaskOld { get { return taskOld; } set { taskOld = value; } }
            public Task TaskNew { get { return taskNew; } set { taskNew = value; } }
     
     
     
        }

    internal class Task
        {
            internal Task() { }
     
            private Guid id = Guid.NewGuid();
            private string description;
     
            public Guid ID { get { return id; } }
            public string Description { get { return description; } set { description = value; } }
     
            public override string ToString()
            {
                return Description;
            }
     
        }


    I have found
    no example for this purpose. For help, I would be grateful.
    Christian Rudat
  2. Peter
    Admin
    Peter avatar
    1157 posts

    Posted 01 Mar 2013 Link to this post

    Hello Cristian,

    Thank you for writing.

    I am not sure that I understand your question clearly enough. However, I have prepared a sample with ComboBox 
    which displays objects of type Cars where Cars are based on the selection in the previous cell named Country. For example, if user selects Germany in the ComboBox the next ComboBox will display only Opel and VW not a Fiat. Please, refer to the attached project.

    If this is not fit to your case, I would kindly ask you to send me an example project or a more detailed info on your requirements. 

    I hope this will be useful. Should you need further assistance, I would be glad to help.

    Kind regards,
    Peter
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Join us for a FREE webinar to see all the new stuff in action.

    Interested, but can’t attend? Register anyway and we’ll send you the recording.
  3. Christian
    Christian avatar
    81 posts
    Member since:
    Aug 2008

    Posted 18 Mar 2013 Link to this post

    Hello Peter,
    thanks for your hint. But my problem is still there. After starting my application the column with the combobox is empty (gridlist.jpg). After changing a value in a row I get an error (gridError1.jpg).
    My source code follows:

    using System;
    using Telerik.WinControls.UI;
    using System.Linq;
     
    namespace Grid_Test
    {
        public partial class frmEmployeeListing : Telerik.WinControls.UI.RadForm
        {
            
            public frmEmployeeListing()
            {
                InitializeComponent();
            }
             
            private void GetTestData()
            {
                TestData.TestDataGenerator.GenerateTestData(1000);
                gridEmployeeListing.DataSource = TestData.DataAccessLayer.EmployeeList;
                gridEmployeeListing.BestFitColumns();
            }
             
            private void frmMitarbeiterlister_Load(object sender, EventArgs e)
            {  
                GetComboBox();
                GetTestData();
            }
     
            private void GetComboBox()
            {
                GridViewComboBoxColumn cbTask = new GridViewComboBoxColumn();
                cbTask.UniqueName = "Task2";
                cbTask.HeaderText = "Task Number 2";
                cbTask.DataSource = TestData.DataAccessLayer.TaskCatalog;
                cbTask.ValueMember = "ID";
                cbTask.DisplayMember = "Description";
                cbTask.FieldName = "Task2"; // Name in the employee-class
                 
                gridEmployeeListing.MasterTemplate.Columns.Add(cbTask);
     
                 
            }
        }
    }

    My class has the following structure:
    namespace Grid_Test.TestData
    {
        internal class Employee
        {
            internal Employee() { }
     
            private Guid id = Guid.NewGuid();
            private string firstname;
            private string lastname;
            private DateTime birthDay;
            private Task taskOld;
            private Task taskNew;
     
            public Guid ID { get { return id; } }
            public string Firstname { get { return firstname; } set { firstname = value; } }
            public string Lastname { get { return lastname; } set { lastname = value; } }
            public DateTime BirthDay { get { return birthDay; } set { birthDay = value; } }
            public Task TaskOld { get { return taskOld; } set { taskOld = value; } }
            public Task TaskNew { get { return taskNew; } set { taskNew = value; } }
            public Task Task2 { get; set; }
     
        }
    }

    For help, I would grateful.
    Christian
  4. Peter
    Admin
    Peter avatar
    1157 posts

    Posted 20 Mar 2013 Link to this post

    Hello Cristian,

    Thank you for writing back and for the provided details.

    Despite my efforts, I was not able to reproduce the issue using the provided classes. I am using version 2012.3 220. I suspect that something related to your application is what causes such behavior. Could you, create a sample project that replicates the behavior on your side, so that we can investigate it further.

    I am looking forward to your reply.

    Greetings,
    Peter
    the Telerik team
    WinForms Q1 2013 boasts PivotGrid, PDF Viewer, Chart enhancements and more. Check out all of the latest highlights.
Back to Top