RadGridView Combo box column auto selection issue

4 posts, 1 answers
  1. Chandra Sekhar
    Chandra Sekhar avatar
    5 posts
    Member since:
    Sep 2016

    Posted 10 Oct Link to this post

    Hi,

    I have a radgridview control which has a binding of a data set (A), In a specific scenario couple of columns in A which has a value in it should show in a combo box control which actually have a set of different possible values in it. I have separate data sets(B & C) bound for those combo box columns. However the current value of the column from A should automatically select in the appropriate value of combo boxes of ( B & C) when I load the data. How can I achieve this. Below is the sample code I have.

    dgvLocations.DataSource = _LocationBo.Do.Table.DefaultView;  // Main datagridview control data source - A

     

    GridViewComboBoxColumn configColumn = new GridViewComboBoxColumn();
    dgvLocations.MasterTemplate.Columns.Add(configColumn);
    configColumn.HeaderText = "Configuration";
    configColumn.DataSource = _LocationConfigCdBo.Do.Table.DefaultView;
    configColumn.FieldName = LocationDo.V_ConfigurationColumn;                 // Column name mapping from the A dataset
    configColumn.ValueMember = LocationConfigCdDo.TypeCdColumn;           // Column name mapping from the B dataset
    configColumn.DisplayMember = LocationConfigCdDo.DescColumn;
    configColumn.Name = LocationDo.V_ConfigurationColumn;

     

    The combo box was successfully loading the values from the dataset B, however it is not showing the selected value from the A. Please advice.

    -Chandra.

  2. Answer
    Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 11 Oct Link to this post

    Hello Chandra,

    Thank you for writing.

    If I understand correctly you are binding the grid to the A data source and you have two other sources for the combo columns. However the values are not synchronized when the grid is loaded, is this correct?

    In this case, you should make sure that the Field and the ValueMemer have the same data type. Here is a complete example for this:
    public partial class RadForm1 : Telerik.WinControls.UI.RadForm
    {
        public RadForm1()
        {
            InitializeComponent();
            BindingList<Product> data = new BindingList<Product>();
            for (int i = 0; i < 10; i++)
            {
                data.Add(new Product() { CategoryId = i, ProductName = "Product" + i });
            }
     
            radGridView1.AutoGenerateColumns = false;
            radGridView1.DataSource = data;
     
            BindingList<Category> categories = new BindingList<Category>();
            for (int i = 0; i < 10; i++)
            {
                categories.Add(new Category() { CategoryName = "Category " + i, Id = i });
            }
     
            GridViewComboBoxColumn configColumn = new GridViewComboBoxColumn();
            radGridView1.Columns.Add(configColumn);
            configColumn.HeaderText = "Configuration";
            configColumn.DataSource = categories;
            configColumn.FieldName = "CategoryId";
            configColumn.ValueMember = "Id";
            configColumn.DisplayMember = "CategoryName";
        }
    }
    class Product
    {
        public string ProductName { get; set; }
        public int CategoryId { get; set; }
    }
    class Category
    {
        public int Id { get; set; }
        public string CategoryName { get; set; }
    }

    I hope this will be useful. 

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Chandra Sekhar
    Chandra Sekhar avatar
    5 posts
    Member since:
    Sep 2016

    Posted 12 Oct in reply to Dimitar Link to this post

    Thank you Dimitar. That was really helpful for me. Actually i was doing the same thing but unknowingly used different FieldName, I realized my mistake only after your sample. Thanks again.
  5. Dimitar
    Admin
    Dimitar avatar
    1415 posts

    Posted 13 Oct Link to this post

    Hello Chandra,

    I am glad I could be of help. Let us know if you have any other questions.

    Regards,
    Dimitar
    Telerik by Progress
    Check out the Windows Forms project converter, which aids the conversion process from standard Windows Forms applications written in C# or VB to Telerik UI for WinForms.For more information check out this blog post and share your thoughts.
Back to Top