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

RadGridView Combo box column auto selection issue

3 Answers 84 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Chandra Sekhar
Top achievements
Rank 1
Chandra Sekhar asked on 10 Oct 2016, 03:23 PM

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.

3 Answers, 1 is accepted

Sort by
0
Accepted
Dimitar
Telerik team
answered on 11 Oct 2016, 09:38 AM
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.
0
Chandra Sekhar
Top achievements
Rank 1
answered on 12 Oct 2016, 08:19 PM
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.
0
Dimitar
Telerik team
answered on 13 Oct 2016, 01:46 PM
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.
Tags
GridView
Asked by
Chandra Sekhar
Top achievements
Rank 1
Answers by
Dimitar
Telerik team
Chandra Sekhar
Top achievements
Rank 1
Share this question
or