Thanks for reply
5 Answers, 1 is accepted
Thank you for writing.
Please refer to the following article which explains how to achieve the desired functionality: http://www.telerik.com/help/winforms/gridview-populating-with-data-binding-to-sub-objects.html.
I hope that you find this information helpful.
Regards,
Stefan
the Telerik team
Hi, sorry for writting in a old post.
I write here because I coudn't open a new thread about my question and it is related to this topic and I didn't find this in the domuentation.
I am trying to bind a property of one class with the fieldName property.
I have this class:
Public Class Test Public Property Name as String Public Property timesName(i as Integer) as String Get return Name & i End Get End PropertyEnd ClassI have no problem binding the data with the property Name like that:
column.fieldName = "Test.Name"
But I'd like to bind a different value in each diferent column. I tried this:
column1.fieldName = "timesName(1)"column2.fieldName = "timesName(2)"
Is there any way to do this?
Can you please clarify what you do mean by "But I'd like to bind a different value in each different column. I tried this:". Also, can you put a small example with couple test records and a mockup of what you expect to see in the grid.
I am looking forward to your reply.
Regards,
Stefan
Telerik
I'd like to assign a property that has a parameter, in order to have a different value in each column, but using the same property.
My question is if it's possible to assign a property that needs a parameter, like timesName(i as Integer).
In my real problem I have a Class like that:
Public Class Test Private list As List(Of String) Public Property Title as String Public ReadOnly Property Item(i as Integer) as String Get return list.Item(i) End Get End PropertyEnd ClassIs it possible to have to have a row that contains the title in the first column and (assuming that I always have 5 elemnts in my list), 5 columns with the Strings contained in my list.
I tried something like:
For i as Integer = 0 to 5 Dim column As New Telerik.WinControls.UI.GridViewTextBoxColumn("List" & i) laboratorioColumn.FieldName = "Item(" & i & ")" grid.Columns.Add(laboratorioColumn)End ForBut it's not working.
Thanks, Joan.
In order to display the values in separate columns, you will have to have a separate public property for each of the columns. RadGridView uses the CurrencyManager.GetItemProperties method to read the object and the indexer is not returned as a in this case, hence the need for separate properties for the different columns. Here is a small example:
Protected Overrides Sub OnLoad(e As EventArgs) MyBase.OnLoad(e) AddGrid() Dim array As TestClass() = New TestClass(0) {} Dim test As New TestClass() test.Title = "test title" array(0) = test Dim col1 As New GridViewTextBoxColumn() col1.FieldName = "Title" radGridView1.Columns.Add(col1) Dim col2 As New GridViewTextBoxColumn() col2.FieldName = "MyProperty1" radGridView1.Columns.Add(col2) Dim col3 As New GridViewTextBoxColumn() col3.FieldName = "MyProperty2" radGridView1.Columns.Add(col3) Dim col4 As New GridViewTextBoxColumn() col4.FieldName = "MyProperty3" radGridView1.Columns.Add(col4) radGridView1.AutoGenerateColumns = False radGridView1.DataSource = arrayEnd SubPublic Class TestClass Private list As List(Of String) Public Sub New() list = New List(Of String)() list.Add("one") list.Add("two") list.Add("three") End Sub Public Property Title() As String Get Return m_Title End Get Set m_Title = Value End Set End Property Private m_Title As String Public ReadOnly Property MyProperty1() As String Get Return list(0) End Get End Property Public ReadOnly Property MyProperty2() As String Get Return list(1) End Get End Property Public ReadOnly Property MyProperty3() As String Get Return list(2) End Get End PropertyEnd ClassI hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.
Regards,
Stefan
Telerik
