I'm trying to create an editable grid, and are experiencing the following error when I enter one in a cell: Parameter count mismatch. This only occurs if the gridview is empty, if there is at least one row the problem does not occur. What should I do?
RadControls version: 2010.1.422.1040
Thanks,
Paulo Corrêa
using System; |
using System.Collections.Generic; |
using System.Linq; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using System.ComponentModel; |
using System.ComponentModel.DataAnnotations; |
namespace RadGridViewWithComboBoxColumn |
{ |
public partial class MainPage : UserControl |
{ |
public MainPage() |
{ |
InitializeComponent(); |
} |
} |
public class MainPageViewModel |
{ |
public MainPageViewModel() |
{ |
Items = new List<Item>(); |
//Items.Add(new Item() { Name = "Item 1" }); |
} |
public List<Item> Items { get; set; } |
} |
public class Item |
{ |
private Guid _id; |
public Guid Id |
{ |
get { return _id; } |
set |
{ |
if (_id != value) |
{ |
_id = value; |
} |
} |
} |
private string _name; |
[StringLength(100)] |
[CustomRequired(ErrorMessage = "Name must be informed")] |
[Display(Name = "Name", Description = "Name")] |
public string Name |
{ |
get { return _name; } |
set |
{ |
if (_name != value) |
{ |
_name = value; |
} |
} |
} |
private Guid _colorId1; |
[CustomRequired(ErrorMessage = "Color 1 must be informed")] |
[Display(Name = "Color 1", Description = "Color 1")] |
public Guid ColorId1 |
{ |
get { return _colorId1; } |
set |
{ |
if (_colorId1 != value) |
{ |
_colorId1 = value; |
} |
} |
} |
private Guid _colorId2; |
[CustomRequired(ErrorMessage = "Color 2 must be informed")] |
[Display(Name = "Color 2", Description = "Color 2")] |
public Guid ColorId2 |
{ |
get { return _colorId2; } |
set |
{ |
if (_colorId2 != value) |
{ |
_colorId2 = value; |
} |
} |
} |
private Guid _colorId3; |
[RadGridViewWithComboBoxColumn.Required(ErrorMessage = "Color 3 must be informed")] |
[Display(Name = "Color 3", Description = "Color 3")] |
public Guid ColorId3 |
{ |
get { return _colorId3; } |
set |
{ |
if (_colorId3 != value) |
{ |
_colorId3 = value; |
} |
} |
} |
} |
public class Color |
{ |
private Guid _id; |
public Guid Id |
{ |
get { return _id; } |
set |
{ |
if (_id != value) |
{ |
_id = value; |
} |
} |
} |
private string _name; |
public string Name |
{ |
get { return _name; } |
set |
{ |
if (_name != value) |
{ |
_name = value; |
} |
} |
} |
} |
public class DataSource |
{ |
public DataSource() |
{ |
Colors = new List<Color>(); |
Colors.Add(new Color() { Id = Guid.NewGuid(), Name = "Green" }); |
Colors.Add(new Color() { Id = Guid.NewGuid(), Name = "Blue" }); |
Colors.Add(new Color() { Id = Guid.NewGuid(), Name = "Yellow" }); |
Colors.Add(new Color() { Id = Guid.NewGuid(), Name = "Gray" }); |
Colors.Add(new Color() { Id = Guid.NewGuid(), Name = "White" }); |
} |
public List<Color> Colors { get; set; } |
} |
} |
<UserControl x:Class="RadGridViewWithComboBoxColumn.MainPage" |
xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation" |
xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" |
xmlns:d="http://schemas.microsoft.com/expression/blend/2008" |
xmlns:mc="http://schemas.openxmlformats.org/markup-compatibility/2006" |
xmlns:local="clr-namespace:RadGridViewWithComboBoxColumn" |
mc:Ignorable="d" |
d:DesignHeight="300" d:DesignWidth="400" xmlns:telerik="http://schemas.telerik.com/2008/xaml/presentation"> |
<UserControl.Resources> |
<local:GuidConverter x:Key="GuidConverter"/> |
<local:DataSource x:Key="DataSource"/> |
<local:MainPageViewModel x:Key="ViewModel"/> |
</UserControl.Resources> |
<Grid x:Name="LayoutRoot" Background="White" d:DataContext="{d:DesignInstance Type=local:MainPageViewModel, IsDesignTimeCreatable=True}"> |
<telerik:RadGridView Name="radGridView1" AutoGenerateColumns="False" ShowInsertRow="True" CanUserInsertRows="True" ShowGroupPanel="False" |
DataContext="{Binding Source={StaticResource ViewModel}}" ItemsSource="{Binding Items}"> |
<telerik:RadGridView.Columns> |
<telerik:GridViewDataColumn Header="Nome" UniqueName="" Width="300" DataMemberBinding="{Binding Name}"> |
</telerik:GridViewDataColumn> |
<telerik:GridViewComboBoxColumn Header="Tipo" Width="145" DataMemberBinding="{Binding ColorId1, Converter={StaticResource GuidConverter}}" |
UniqueName="Color1" SelectedValueMemberPath="Id" |
DisplayMemberPath="Name" ItemsSourceBinding="{Binding Path=Colors, Source={StaticResource DataSource}}"> |
</telerik:GridViewComboBoxColumn> |
<telerik:GridViewComboBoxColumn Header="Tipo" Width="145" DataMemberBinding="{Binding ColorId2, Converter={StaticResource GuidConverter}}" |
UniqueName="Color2" SelectedValueMemberPath="Id" |
DisplayMemberPath="Name" ItemsSourceBinding="{Binding Path=Colors, Source={StaticResource DataSource}}"> |
</telerik:GridViewComboBoxColumn> |
<telerik:GridViewComboBoxColumn Header="Tipo" Width="145" DataMemberBinding="{Binding ColorId3, Converter={StaticResource GuidConverter}}" |
UniqueName="Color3" SelectedValueMemberPath="Id" |
DisplayMemberPath="Name" ItemsSourceBinding="{Binding Path=Colors, Source={StaticResource DataSource}}"> |
</telerik:GridViewComboBoxColumn> |
</telerik:RadGridView.Columns> |
</telerik:RadGridView> |
</Grid> |
</UserControl> |
using System; |
using System.Net; |
using System.Windows; |
using System.Windows.Controls; |
using System.Windows.Documents; |
using System.Windows.Ink; |
using System.Windows.Input; |
using System.Windows.Media; |
using System.Windows.Media.Animation; |
using System.Windows.Shapes; |
using System.Windows.Data; |
using System.Globalization; |
namespace RadGridViewWithComboBoxColumn |
{ |
public class GuidConverter : IValueConverter |
{ |
public object Convert(object value, Type targetType, object parameter, CultureInfo culture) |
{ |
Guid guid = new Guid(); |
if (value != null) |
guid = (Guid)value; |
if (guid.Equals(new Guid())) |
return DependencyProperty.UnsetValue; |
return guid; |
} |
public object ConvertBack(object value, Type targetType, object parameter, CultureInfo culture) |
{ |
if (value == null) |
return new Guid(); |
return value; |
} |
} |
} |
public class CustomRequiredAttribute : System.ComponentModel.DataAnnotations.RequiredAttribute |
{ |
protected override ValidationResult IsValid(object value, ValidationContext validationContext) |
{ |
return base.IsValid(value is Guid && value.Equals(new Guid()) ? null : value, validationContext); |
} |
} |
RadControls version: 2010.1.422.1040
Thanks,
Paulo Corrêa