C1TreeView DisplayFieldName

Posted by: goran.gustafsson on 2 April 2024, 8:21 pm EST

    • Post Options:
    • Link

    Posted 2 April 2024, 8:21 pm EST

    Hi. I have a problem with multicolumns C1TreeView. I have a text in the first column and want a number in the second column, but I get either the value from the first column or an empty field depending what I do with DisplayFieldName. I am creating the nodes in code and am not using Binding (in this case). I am trying “DisplayFieldName” in different ways but it seems I can not create it correct to get the number viewed in the column. I have made a simple C#-project in Visual Studio 2022 with C1TreeView for .NET 8. Can someone see what I am doing wrong and maybe correct it or give me a hint of what to do? When I click on a child node I transfer the data to some labels and the number to a textbox. I want to be able to change the number in the textbox and update the column in the selected child node when I click on the Save button. But since I can not get the number in the first place this is not possible.

    I hope someone can help.

    Thanks and best regards!

    WinFormsTestTree.zip

  • Posted 3 April 2024, 6:19 pm EST

    Hi Goran,

    Thanks a lot for sharing the sample project for a better understanding of your implementation.

    Here, you are trying to use the C1TreeView similar to a Grid, which is causing this behavior. FYI, the C1TreeView does not work like a grid where each column cell stores its value independently. Instead, each node of the C1TreeView can store only a single value (which can be of any DataType).

    If you want different columns to show different values, you can create a custom class with Text and Number properties and assign its objects as the value of the nodes. The columns will show the values from these objects based on their DisplayFieldName property. Please see the updated sample project which works as per your requirements.

    Attachment: WinFormsTestTree_Updated.zip

    Best Regards,

    Kartik

  • Posted 3 April 2024, 6:37 pm EST

    Hi Kartik.

    Thank you so much for the updated project and your explanations. When I see your extensions of my code I get it. This does exactly what I want to do (and was trying to do). I will now implement this in my main project. Thanks again!

  • Posted 3 April 2024, 6:43 pm EST

    Hi Goran,

    We are happy to know that we could help :-).

    Kind Regards,

    Kartik

Need extra support?

Upgrade your support plan and get personal unlimited phone support with our customer engagement team

Learn More

Forum Channels