I've tried to put this question in the forum but the page keeps disappearing after I click "submit", so here I am...
I have a 3 column GridView and the GridViewComboBoxColumn is not binding correctly. I've set the following for the grid.
- DisplayMember = Color
- ValueMember = Id
- DataType = System.ComponentModel.BindingList`1[TelerikGridViewTests.Models.ColorViewModel]
When I run the application I see "System.ComponentModel.BindingList`1[TelerikGridViewTests.Models.ColorViewModel]" instead of the object within my model. For my other 2 columns in the grid (a decimal and a string) those are displayed just fine.
Here is my model code...
using System.ComponentModel;
namespace TelerikGridViewTests.Models
{
public class CarsViewModel : ViewModelBase
{
public CarsViewModel()
{
_cars = new BindingList<CarViewModel>();
_cars.Add(new CarViewModel()
{
Id = 0m,
Description = "Ford",
Colors = new ColorsViewModel().Colors,
});
_cars.Add(new CarViewModel()
{
Id = 1m,
Description = "Chevy",
Colors = new ColorsViewModel().Colors,
});
_cars.Add(new CarViewModel()
{
Id = 2m,
Description = "Dodge",
Colors = new ColorsViewModel().Colors,
});
}
BindingList<CarViewModel> _cars;
public BindingList<CarViewModel> Cars { get { return _cars; } set { _cars = value; } }
}
public class CarViewModel : ViewModelBase
{
public decimal Id { get; set; }
public string Description { get; set; }
BindingList<ColorViewModel> _colors;
public BindingList<ColorViewModel> Colors
{
get { return _colors; }
set { _colors = value; }
}
}
public class ColorsViewModel : ViewModelBase
{
public ColorsViewModel()
{
Colors = new BindingList<ColorViewModel>();
Colors.Add(new ColorViewModel()
{
Id = 1,
Color = "Blue",
});
Colors.Add(new ColorViewModel()
{
Id = 2,
Color = "Red",
});
Colors.Add(new ColorViewModel()
{
Id = 3,
Color = "Green",
});
Colors.Add(new ColorViewModel()
{
Id = 4,
Color = "Yellow",
});
}
public BindingList<ColorViewModel> Colors { get; set; }
}
public class ColorViewModel : ViewModelBase
{
public int Id { get; set; }
public string Color { get; set; }
}
}
and code which binds the model..
using System.ComponentModel;
using System.Windows.Forms;
using TelerikGridViewTests.Models;
namespace TelerikGridViewTests
{
public partial class Form1 : Form
{
public Form1()
{
InitializeComponent();
BindingList<CarViewModel> _cars = new CarsViewModel().Cars;
radGridView1.DataSource = _cars;
}
}
}