GridViewTextBoxColumn FieldName - path to referenced object

6 posts, 0 answers
  1. Karel
    Karel avatar
    4 posts
    Member since:
    Jul 2012

    Posted 16 Jul 2012 Link to this post

    I am adding columns manually to the gridview master template. For this I am using GridViewTextBoxColumn. Let's say I have object Product which references object ProductCategory. In the gridview i would like to show information about product including the name of the product's category. I tried the dot notation like FieldName = "ProductCategory.Name" but it's not working. Is it possible handle this situation or I would have to use some DTO?

    Thanks for reply
  2. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 19 Jul 2012 Link to this post

    Hi Karel,

    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
    RadControls for WinForms Q2'12 release is now live! Check out what's new or download a free trial >>
  3. UI for WinForms is Visual Studio 2017 Ready
  4. Joan
    Joan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 23 Jul 2015 Link to this post

    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 Property
    End Class

    I 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?

  5. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 24 Jul 2015 Link to this post

    Hello Joan,

    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
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
  6. Joan
    Joan avatar
    2 posts
    Member since:
    Jul 2015

    Posted 24 Jul 2015 in reply to Stefan Link to this post

    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 Property
     
    End Class

    Is 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 For

    But it's not working.

    Thanks, Joan.

     

     

  7. Stefan
    Admin
    Stefan avatar
    2891 posts

    Posted 24 Jul 2015 Link to this post

    Hello 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 properties, and the indexer is not returned as a property 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 = array
     
    End Sub
     
    Public 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 Property
    End Class

    I hope that you find this information useful. Should you have any other questions, do not hesitate to contact us.

    Regards,
    Stefan
    Telerik
    Do you want to have your say when we set our development plans? Do you want to know when a feature you care about is added or when a bug fixed? Explore the Telerik Feedback Portal and vote to affect the priority of the items
Back to Top
UI for WinForms is Visual Studio 2017 Ready