How to use Indexer Property in New Release

4 posts, 0 answers
  1. Nik
    Nik avatar
    14 posts
    Member since:
    Jan 2007

    Posted 14 Apr 2009 Link to this post

    Hi there,

    I have download a new release for silverlight 2.0 (2009 1 0413).

    How can I use the indexer property with Gridview.

    I have one Class
    Public Class Record

        Private _Columns As Object
        Public Property Column(ByVal name As String) As Object
            Get
                Return _Columns(name)
            End Get
            Set(ByVal value As Object)
                _Columns(name) = value
            End Set
        End Property

    End Class

    I am assigning list(of Record) to itemsource to Grid.

    How can bind this to column.
    like column should bind to Column("ID"), Column("Name")
    Please suggest me.

    Any help would really appreciated.






  2. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 17 Apr 2009 Link to this post

    Hi Nik,

    Our GridViewDataColumns have a property DataMemberBinding that you can usually use to address such scenarios. Unfortunately Silverlight bindings do not support indexers so you cannot do the following:
    <telerikGrid:RadGridView Name="RadGridView1" AutoGenerateColumns="False">  
        <telerikGrid:RadGridView.Columns> 
            <telerikGrid:GridViewDataColumn   
                DataMemberBinding="{Binding Path=Columns[ID]}"/>  
        </telerikGrid:RadGridView.Columns> 
    </telerikGrid:RadGridView> 
    There is a workaround, though, that you could try. You could provide a ValueConverter to the DataMemberBinding that will access the indexer property and return a desired value.
    Ultimately the XAML looks like that:
    <telerikGrid:RadGridView Name="RadGridView1" AutoGenerateColumns="False">  
        <telerikGrid:RadGridView.Columns> 
            <telerikGrid:GridViewDataColumn   
                DataMemberBinding="{Binding Converter={StaticResource IndexerConverter}, ConverterParameter=2}"/>  
        </telerikGrid:RadGridView.Columns> 
    </telerikGrid:RadGridView> 
    The ConverterParameter specifies the index of the column that we want to bind to.   
    I have prepared a sample application that demonstrates that approach.

    Greetings,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
  3. DevCraft banner
  4. Nik
    Nik avatar
    14 posts
    Member since:
    Jan 2007

    Posted 17 Apr 2009 Link to this post

    Hi,

    Thanks for the prompt reply.

    I was looking for the TwoWay Binding. here in example you have created OneWay Binding.

    Can you please help in doing TwoWay Binding.
  5. Milan
    Admin
    Milan avatar
    1989 posts

    Posted 21 Apr 2009 Link to this post

    Hello Nik,

    Making TwoWay binding to work requires a lot of nasty code, still, I have modified the original application and now TwoWay binding is used. Given Silverlight's binding limitations I would recommend that you use a different approach - for example, change the way your data is structured so that you will not have to use indexers.

    Best wishes,
    Milan
    the Telerik team

    Instantly find answers to your questions on the new Telerik Support Portal.
    Check out the tips for optimizing your support resource searches.
Back to Top