C1TreeView Winforms. Added node to databound control. Cannot select in code.

Posted by: johntam on 17 April 2019, 6:38 am EST

  • Posted 17 April 2019, 6:38 am EST

    Winforms C1Tree View v4.0.20191.359

    I have a datatable bound to the TreeView and it renders properly.

    Table is
    ClassID (not displayed used for database to assemble the data)
    Level number (not displayed used for database to assemble the data)
    Parent ID
    Display Name

    The ID, and display name are properly bound. Again it displays properly.

    The following VB.NET code is used to respond to a context menu that is activted on a right click:

        Private Sub tsmiNewFolder_Click(sender As Object, e As EventArgs) Handles tsmiNewFolder.Click
    Dim _newDR As DataRow = DirectCast(tvBrowse.BindingInfo.DataSource, DataTable).NewRow()
    _newDR("F_NAME") = "New Folder"
    _newDR("TR_LEVEL") = CInt(_activeDR("TR_LEVEL")) + 1
    _newDR("TR_PARENT_F_ID") = CInt(_activeDR("TR_F_ID"))
    _newDR("TR_F_ID") = -1
    DirectCast(tvBrowse.BindingInfo.DataSource, DataTable).Rows.Add(_newDR)
    End Sub

    _activeDR is populated by doing a getvalue on the selected row in the MouseUp event, and is correctly.

    What I cannot do is select the newly created node in order to allow the end user to type in the name of the folder. I don't want to create a popup.

    I cannot find a method that gives me the index of the newly created node.

    As an aside I tried to create a node and set its value to the data row, but that creates an empty row in addition to the new row in the data table. The above code highlights and edits the parent node of the newly created node.

    Again, the documentation and samples don't appear to demonstrate this functionality. A search of the forum also did not appear to give a solution.

    Please assist.

  • Replied 21 April 2019, 6:18 pm EST


    Apologies for the delayed response.

    With the current control it looks like a cell in the newly added row cannot be programmatically put in edit mode. To confirm this, I am discussing your requirements with the developers [ID: 375798].
    I'll update this thread with the information they share about this issue.

  • Replied 23 April 2019, 4:46 am EST

    This is a show stopper for me. Is there ANY way to select a node based on a value in the underlying dataset? At this point I am ready to clear the nodes, reload, and hunt down the node with the key value. It will look horrible to the end user, but at least it will work.
  • Replied 23 April 2019, 5:42 pm EST


    In your original post you described your requirement to select the newly added node and forcefully make it enter Edit mode. So like I mentioned earlier, it is currently not possible to programmatically select a node and edit the same.
    However as we understand, in the last response you mention to just select a node based on its underlying key value.
    If that is so, you can achieve this with C1TreeView by traversing it's Nodes collection and using its GetValue method to get underlying value.

    Please refer attached sample and click its Button to select a specific node.

  • Replied 24 April 2019, 7:49 am EST

    I was able to make this PARTIALLY work. I wrote code to traverse the nodes and unselect all nodes where selected is true. I then traverse the nodes a second time and use the GetValue method to find the matching key. I then set selected to true and exit.

    This appears to select the node in question, but if I call BeginEdit(), the previously selected node goes into edit mode. If I read your note correctly, the feature to select and edit a node in code does not yet exist.

    I'd appreciate a timeline. One would think that this is not a huge amount of time or code to implement. I can postulate a method that should be able to do so in under 25 lines.
  • Replied 24 April 2019, 11:10 pm EST


    Yes, you understand that correctly.
    Currently in C1TreeView, the ability to edit the selected node is not working and the development team is investigating over it. I have inquired them about an ETA for this and will update this thread as soon as we have some information.

    Kind Regards,
  • Marked as Answer

    Replied 28 April 2019, 3:22 pm EST


    Developers have been able to find a solution for your requirement. The solution is not through any direct properties/methods but works exactly as you needed, as per my tests.
    I'd request to refer the attached application and verify it's working.

Need extra support?

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

Learn More

Forum Channels