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

Column Insert Bug

1 Answer 24 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Josh
Top achievements
Rank 1
Josh asked on 25 Mar 2011, 05:59 PM
I am receiving the error "Invalid Binding Path; character 1 in 1" when I try to insert a column into a grid.  This is causing problems in several areas of a complex application, however, I finally narrowed it down to a small sample of code that can reproduce it.  In order to reproduce the error in my sample application below simply click the "Add Test Col" button at the top first and then click "Insert Test Col" second.  The first button click is successful, the second one results in the error previously stated.  I am using Q1 2011 and the issue seems to me to be somehow related to the UniqueName property and the Columns.Insert method.  The Columns.Add method seems to work fine.  The issue does not appear to be browser specific.

The xaml
<UserControl x:Class="SpectrumSL.ucTest"
    xmlns:telerik="clr-namespace:Telerik.Windows.Controls;assembly=Telerik.Windows.Controls.GridView"
    DataContext="{Binding RelativeSource={RelativeSource Self}}" x:Name="root">
    <Grid x:Name="LayoutRoot" Background="White">
        <Grid.RowDefinitions>
            <RowDefinition Height="Auto" />
            <RowDefinition Height="Auto" />
            <RowDefinition Height="*" />
        </Grid.RowDefinitions>
        <Button Grid.Row="0" x:Name="btnAddTestCol" Content="Add Test Col" Click="btnAddTestCol_Click" FontSize="14"/>
        <Button Grid.Row="1" x:Name="btnInsertTestCol" Content="Insert Test Col" Click="btnInsertTestCol_Click" FontSize="14"/>
        <telerik:RadGridView Grid.Row="2" x:Name="TestGrid" ItemsSource="{Binding TestValues}"/>
    </Grid>
</UserControl>

The codebehind
Public Class ucTest
    Inherits UserControl
 
    Public Sub New()
        InitializeComponent()
    End Sub
 
    Private Sub ucNomination_Loaded(sender As Object, e As System.Windows.RoutedEventArgs) Handles Me.Loaded
        TestValues.Add(New Test With {.TestProperty = 1})
    End Sub
 
    Private Sub btnAddTestCol_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim col As New GridViewDataColumn
        col.UniqueName = "1"
        col.Header = "Added Column"
        TestGrid.Columns.Add(col)
    End Sub
 
    Private Sub btnInsertTestCol_Click(sender As System.Object, e As System.Windows.RoutedEventArgs)
        Dim col As New GridViewDataColumn
        col.UniqueName = "2"
        col.Header = "Inserted Column"
        TestGrid.Columns.Insert(0, col)
    End Sub
 
    Public Property TestValues() As New ObservableCollection(Of Test)
 
    Public Class Test
        Public Property TestProperty() As Integer
    End Class
 
End Class

Thanks,

-Josh

1 Answer, 1 is accepted

Sort by
0
Pavel Pavlov
Telerik team
answered on 31 Mar 2011, 12:28 PM
Hello Josh,

I think I found what is causing the problem .  When you are adding columns you are not setting their DataMemberBinding.
In such case RadGridView will try to use the UniqueName to set the binding. Since the Unique name contains a numeric value ( which is not a valid name) - you get the error.

Now the solution :
In case you need  data bound cells - simply try setting the DataMemberBinding of the columns to point to the right property.

In case you need no data bound cells - just use GridViewColumn , instead of GridViewDataColumn.

Hope that helps.

Best wishes,
Pavel Pavlov
the Telerik team
Tags
GridView
Asked by
Josh
Top achievements
Rank 1
Answers by
Pavel Pavlov
Telerik team
Share this question
or