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

RadDataForm and ComboBox problem

1 Answer 122 Views
DataForm
This is a migrated thread and some comments may be shown as answers.
David
Top achievements
Rank 1
David asked on 03 Nov 2013, 12:19 PM
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

1 Answer, 1 is accepted

Sort by
0
Accepted
Maya
Telerik team
answered on 04 Nov 2013, 08:43 AM
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 >>
Tags
DataForm
Asked by
David
Top achievements
Rank 1
Answers by
Maya
Telerik team
Share this question
or