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

Problem with init GridViewMultiComboBoxColumn

2 Answers 100 Views
GridView
This is a migrated thread and some comments may be shown as answers.
flisak
Top achievements
Rank 1
flisak asked on 16 Mar 2012, 11:36 AM
Hi,

I have problem with GridViewMultiComboBoxColumn. I using the latest version of telerik package (Q1 2012).

I have two objects:

public class Offer
{
  public Guid Id { get; set; }
  public string OfferNo { get; set; }
  public Customer Client { get; set; }
  public DateTime? DateFrom { get; set; }
  public DateTime? DateTo { get; set; }
}
 
public class Customer
{
  public Guid CustomerId { get; set; }
  public string Name { get; set; }
  public string ShortName { get; set; }
}

When i set GridViewMultiComboBoxColumn for "Client" property then I have exception: Converter can't convert.
If I dont't set ValuMember property, then is no exception, byt choose object in grid don't work.

public Form1()
{
    InitializeComponent();
 
    custs = GridData.GetCustomers(5);
 
    IList offers = GridData.GetGridData(custs);
 
    radGridView1.DataSource = offers;
    SetColumns();
}
 
private void SetColumns()
{
    radGridView1.Columns.Clear();
 
    GridViewDataColumn column = null;
    for (int i = 0; i < 4; i++)
    {
        switch (i)
        {
            case 0:
                column = new GridViewTextBoxColumn("Offer no");
                break;
            case 2:
                column = new GridViewDateTimeColumn("Date from");
                break;
            case 3:
                column = new GridViewDateTimeColumn("Date to");
                break;
            case 1:
                column = new GridViewMultiComboBoxColumn("Client");
                ((GridViewMultiComboBoxColumn)column).FieldName = "Client";                       
                ((GridViewMultiComboBoxColumn)column).DataSource = custs;
                ((GridViewMultiComboBoxColumn)column).DisplayMember = "Name";
                ((GridViewMultiComboBoxColumn)column).ValueMember = "CustomerId";
                break;
        }
 
        column.Width = 150;
        column.IsVisible = true;
        column.ReadOnly = false;
 
        radGridView1.Columns.Add(column);
    }
}

What am I doing wrong?

Best Regards

2 Answers, 1 is accepted

Sort by
0
Accepted
Svett
Telerik team
answered on 19 Mar 2012, 10:38 AM
Hello Krzysztof,

You are trying to bind a custom object to a GridViewMultiCoboBoxColumn. The RadGridView for WinForms does not support that kind of binding out of the box. You should use sub-property binding with combination of CellValidating event in the following way:
GridViewMultiComboBoxColumn column = new GridViewMultiComboBoxColumn("Client.CustomerId");
column.DataSource = custs;
column.DisplayMember = "Name";
column.ValueMember = "CustomerId";
this.radGridView1.Columns.Add(column);

private void radGridView1_CellValidating(object sender, CellValidatingEventArgs e)
{
    RadMultiColumnComboBoxElement mccb = e.ActiveEditor as RadMultiColumnComboBoxElement;
 
    if (mccb != null && e.Column.Name == "Client.CustomerId")
    {
        e.Cancel = true;
        Offer offer = e.Row.DataBoundItem as Offer;
        offer.Client = mccb.EditorControl.CurrentRow.DataBoundItem as Customer;
    }
}

In addition, you should set the CloseEditorWhenValidationFails property of RadGridView to true:
this.radGridView1.CloseEditorWhenValidationFails = true;

I hope this helps.

Greetings,
Svett
the Telerik team
RadControls for WinForms Q1'12 release is now live! Check out what's new or download a free trial >>
0
flisak
Top achievements
Rank 1
answered on 20 Mar 2012, 05:23 PM
Thanks Svett. This works fine!

Regards
Tags
GridView
Asked by
flisak
Top achievements
Rank 1
Answers by
Svett
Telerik team
flisak
Top achievements
Rank 1
Share this question
or