RadDataForm and ComboBox problem

2 posts, 1 answers
  1. David
    David avatar
    2 posts
    Member since:
    Apr 2013

    Posted 03 Nov 2013 Link to this post

    Hi!
    We are amazed with your controls for WPF, specially with RadDataForm.
    But, we have one problem.
    We need ComboBoxField to choose which Company has produced the Product.
    And it's working well, but when we add new product and click OK, a NullReferenceException pops out.
    Our code:
    Company.cs
        class Company : IDataErrorInfo
        {
            public int _id;
            public int id
            {
                get
                {
                    return _id;
                }
                set
                {
                    _id = value;
                }
            }
     
            public string _name;
            public string name
            {
                get
                {
                    return _name;
                }
                set
                {
                    _name= value;
                }
            }
     
            public string Error
            {
                get;
                set;
     
            }
     
            public string this[string columnName]
            {
    // . . .
            }
     
            public static void Add(Company ist)
            {
    // . . .
            }
     
            public static void Edit(Company ist)
            {
    // . . .
            }
     
            public static void Delete(Company ist)
            {
    // . . .
            }
     
            public static List<Company> Get()
            {
    // . . .
              }
    }
    Product.cs
        class Product: IDataErrorInfo
        {
            public int _id;
            public int id
            {
                get
                {
                    return _id;
                }
                set
                {
                    _id = value;
                }
            }
      
            public string _name;
            public string name
            {
                get
                {
                    return _name;
                }
                set
                {
                    _name= value;
                }
            }
     
            public Company _comp;
            public Company comp
            {
                get
                {
                    return _comp;
                }
                set
                {
                    _comp= value;
                }
            }
      
            public string Error
            {
                get;
                set;
      
            }
      
            public string this[string columnName]
            {
    // . . .
            }
      
            public static void Add(Product ist)
            {
    // . . .
            }
      
            public static void Edit(Product ist)
            {
    // . . .
            }
      
            public static void Delete(Product ist)
            {
    // . . .
            }
      
            public static List<Product> Get()
            {
    // . . .
              }
    }
    And our AutoGeneratingField event of RadDataForm:
    private void DataForm1_AutoGeneratingField_1(object sender, Telerik.Windows.Controls.Data.DataForm.AutoGeneratingFieldEventArgs e)
    {
        if (e.PropertyName == "Error" || e.PropertyName == "id")
        {
            e.Cancel = true;
        }
        else if (e.PropertyName == "comp")
        {
            e.DataField = new DataFormComboBoxField()
            {
                ItemsSource = viewModel.companies,
                DisplayMemberPath = "name",
                SelectedValuePath = "id",
                DataMemberBinding = new Binding("comp.id")
                {
                    Mode = BindingMode.TwoWay
                },
                Label = "Company"
            };                       
        }
        e.DataField.DataMemberBinding.ValidatesOnDataErrors = true;
        e.DataField.DataMemberBinding.NotifyOnValidationError = true;
    }
    And once again, this is working OK, but when we proceed with adding new product, NullReferenceException pops out because Company property of Product for adding is null.
    Where we sin?
    P.S: Sorry for our terrible English, we're from Serbia, and we implemented all CRUD operations with RadDataForm events (EditEnded, AddedNewRecord...).
    Thanks in advance!
    DMSoft
  2. Answer
    Maya
    Admin
    Maya avatar
    4062 posts

    Posted 04 Nov 2013 Link to this post

    Hello David,

    I have tried to reproduce the behavior, but without any success. Will it be possible to check out the sample attached and let me know what I am missing ? What are the steps that I need to follow for reproducing the exception ? 

    Regards,
    Maya
    Telerik
    TRY TELERIK'S NEWEST PRODUCT - EQATEC APPLICATION ANALYTICS for WPF.
    Learn what features your users use (or don't use) in your application. Know your audience. Target it better. Develop wisely.
    Sign up for Free application insights >>
  3. UI for WPF is Visual Studio 2017 Ready
Back to Top