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

How to use Indexer Property in New Release

3 Answers 71 Views
GridView
This is a migrated thread and some comments may be shown as answers.
Nik
Top achievements
Rank 1
Nik asked on 14 Apr 2009, 02:01 PM
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.






3 Answers, 1 is accepted

Sort by
0
Milan
Telerik team
answered on 17 Apr 2009, 11:15 AM
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.
0
Nik
Top achievements
Rank 1
answered on 17 Apr 2009, 04:14 PM
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.
0
Milan
Telerik team
answered on 21 Apr 2009, 04:11 PM
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.
Tags
GridView
Asked by
Nik
Top achievements
Rank 1
Answers by
Milan
Telerik team
Nik
Top achievements
Rank 1
Share this question
or