I am trying to transfer the selected items of one combo box to another using following code:
ComboBoxItem shift1Driver = new ComboBoxItem();
shift1Driver.Text = (comboBoxDriverShift1.SelectedItem as ComboBoxItem).Text;
shift1Driver.Value = (comboBoxDriverShift1.SelectedItem as ComboBoxItem).Value.ToString();
comboBoxAccountsDriverName.Items.Add(shift1Driver);
The ComboBoxItem class is user-defined and used to store combo box text and values together.
public class ComboBoxItem
{
public ComboBoxItem()
{
Text = "ComboBoxItem1";
Value = "ComboBoxItem1";
}
public string Text { get; set; }
public object Value { get; set; }
public override string ToString()
{
return Text;
}
}
But the code is throwing NullReferenceException
and I am unable to find a reason for it. The values are being fetched like this from ComboBox:
But not assigning them to
ComboBoxItem
's object shift1Driver
. Please help.