Flexgrid with 3 child VB sample

Posted by: saidnai on 13 August 2020, 1:57 am EST

    • Post Options:
    • Link

    Posted 13 August 2020, 1:57 am EST

    Good day,

    again i need your support for the following challenge to bild a flexgrid that shows:

    1) Parent will be the offer Information:

    Offer no, Customer no, deadline, etc…

    2) 1 child offer position:

    Offer no, offer position no, product, net weight, etc…

    3) 2 child the plant:

    Offer no, Offer Position no, plant no, net weight, etc…

    4) 3 child plan position:

    Offer no, Offer Position no, plant no, plan Position, plan date,

    Net weight, etc…

    It will be great to have a VB samples to build it. That Shows a double click event on each (parent/childs) tho know which has been clicked.

    Thank for your support.

    Best regards

    Said

  • Posted 14 August 2020, 12:56 am EST

    Hi Said,

    You can create the Tree to show the data hierarchically in FlexGrid. You can refer to the FlexGrid’s Product Sample DataTree (Location: .\Documents\ComponentOne Samples\WinForms\C1FlexGrid\VB\DataTree) which shows how you can show the Parent-Child relationship between the data.

    You can handle the double click event of the FlexGrid and get the Flexgrid that was double-clicked with the help of the sender parameter of the event.

    A modified DataTree sample with a DoubleClick event is attached for reference.

    Regards,

    Prabhat Sharma.

    DataTree.zip

  • Posted 18 August 2020, 1:06 am EST - Updated 3 October 2022, 1:24 pm EST

    Dear Prabhat,

    I have tried to open the Project but i get the error attached.

    Can you please support.

    Best regards

    Said

  • Posted 18 August 2020, 6:48 pm EST

    Hi Said,

    Please follow the below-given steps to resolve this issue:

    1: Open project in VS.

    2: Close the Form1.vb designer window.

    3: Go to the Build tab of the VS and click the Clear Solution.

    4: Rebuild the project by clicking Build solution.

    5: Open the Form1.vb designer window, you will see the form’s controls successfully.

    I hope it helps.

    If you need any other help, please let us know.

    Regards,

    Prabhat Sharma.

  • Posted 20 August 2020, 1:47 am EST

    Dear Prabhat,

    I had some problems with lc.exe. So i create a new VB projekt and do similar. I still have 2 event problems even if they are declared as public. I have attahced the new VB project to easily support me.

    Best regards

    Said

    DataTree.zip

  • Posted 20 August 2020, 6:02 pm EST

    Hi,

    The issue with the events is there because instead of using custom FlexGrid i.e. C1FlexDataTree which have these events, you are using C1FlexGrid which doesn’t have these events.

    So you need to make “_flex” C1FlexDataTree instead of C1FlexGrid.

    You have used:-

    Friend WithEvents _flex As C1.Win.C1FlexGrid.C1FlexGrid

    Me._flex = New C1.Win.C1FlexGrid.C1FlexGrid()

    Instead of :

    Friend WithEvents _flex As C1FlexDataTree

    Me._flex = New C1FlexDataTree ()

    A modified sample is attached for reference, please have a look.

    Regards,

    Prabhat Sharma.

    DataTree_Modified.zip

  • Posted 21 August 2020, 1:55 am EST

    Dear Prabhat,

    Thanks a lot. I will come back to you if any support needed. I appreciate it.

    Best regards

    Said

  • Posted 20 June 2022, 9:26 pm EST

    Good day,

    1. I have tried the VB sample attached from Prabhat and adjusted it as needed and it is

      running well. I now need to read/get the value of the each cell and assign different

      back or Text color to each level and also cell if needed.

    2. another question is it also possible to add a fourth level?

    Any support is appreciated.

    Best regards

    Said

  • Posted 21 June 2022, 6:56 pm EST

    Hello,

    We are discussing this issue with the developers and will get back to you with the updates soon.

    [Internal Tracking Id: C1WIN-27622]

    Regards,

    Prabhat Sharma.

  • Posted 21 June 2022, 8:32 pm EST - Updated 3 October 2022, 1:24 pm EST

    Hi,

    hope I understand the requirement correct. Attached is a modified sample (now uses Nuget packages), which listens for the “childgrid is expanded” event. If the childgrid is at level 1, it sets a red backcolor to the cell at row 1:

    In the sample, this is done for all first level child grids. But it should be easy to define the color based on the cell content.

    I listen to the “AfterCollapse” event, which is raised after a child grid is expanded/collapsed:

    
      Private Sub _flex_AfterCollapse(sender As Object, e As RowColEventArgs) Handles _flex.AfterCollapse
        Dim childGrid As C1FlexDataTree = CType(Me._flex.Rows(e.Row).UserData, C1FlexDataTree)
    
        If (childGrid IsNot Nothing) Then
          If (childGrid.level = 1) Then
            Dim rowChild As Integer
            Dim styleRed As CellStyle = childGrid.Styles.Add("Red", childGrid.Styles.Normal)
            styleRed.BackColor = Color.Red
            For rowChild = childGrid.Rows.Fixed To childGrid.Rows.Count
              If (rowChild = 2) Then
                childGrid.SetCellStyle(rowChild, 1, styleRed)
              End If
            Next
          End If
        End If
      End Sub
    
    

    Does this help?

    Wolfgang

    DataTree_Style.zip

  • Posted 21 June 2022, 10:45 pm EST

    Dear Wolfgang,

    The function helps of course for the Cellstyle but I think i didn’t explain well the needed support. sorry.

    The target is to reduce Forms and Flexgrids in the application for various area when using the C1FlexDataTree.

    Following: I have 4 tables,

    Tables 1 contains general informations. This will be level 1, HQ Customer

    information .

    Tables 2 contains variable informations. This will be level 2, ordered products.

    Tables 3 contains variable informations. This will be level 3, Customer plants.

    Tables 4 contains variable informations. This will be level 4, ordered products

    for the plants.

    1. When any child is expanded, it should get a different backcolor/forecolor to see the

      differences between the Levels.
    2. How to read the C1FlexDataTree(_Flex)

      a) Get the value of each Level

      b) Get the value of each Cell.

    Thanks & Best regards

    Na

  • Posted 22 June 2022, 10:23 pm EST

    Hi Said,

    I fear I don’t understand your questions - or the requirements are too vague ;-). The backcolor problem should be solveable with my CellStyle sample. What does not work for you?

    Of course, you can also read data of the child grid. But you can access a child grid only if it is expanded. Collapsed cells don’t contain the child grid.

    The sample uses data binding, so you cannot modify cell values. You would have to modify the underlying datasource.

    Did you ever take a look at “real” trees in C1FlexGrid? Maybe they also work in your situation. The only drawback is that all tree levels must have the same number of columns.

    A sample can be found here: https://github.com/GrapeCity/ComponentOne-WinForms-Samples/tree/master/NetFramework/FlexGrid/CS/TreeNode

    Best regards

    Wolfgang

  • Posted 23 June 2022, 6:57 pm EST - Updated 3 October 2022, 1:24 pm EST

    Hi Wolfgang,

    Thanks for your support. I had a look at the sample. It could be helpfull for other projects. I have made a picture from the system (Web/old .asp) that i need to renew.

    Explanation:[ul][/ul]

    All the levels are of course bind together with the IDs.

    As you said only when the level is expanded. The on dbclick should gives back the level no and also the value of the ID of the selected record(Grid.item(Row,Col)). With this i can open a seperate form and the user can update the date of the level.

    I do not kow if possible to get per each level the on right mouseclick a popup menu (New/Update/Delete/Print)

    Best regards

    Na

  • Posted 27 June 2022, 9:09 pm EST

    Attached is a reworked sample that shows how to add a ContextMenuStrip to the child grid when it is expanded.

    
     Private Sub _flex_AfterCollapse(sender As Object, e As RowColEventArgs) Handles _flex.AfterCollapse
        Dim childGrid As C1FlexDataTree = CType(Me._flex.Rows(e.Row).UserData, C1FlexDataTree)
    
        If (childGrid IsNot Nothing) Then
          If (childGrid.level = 1) Then
            ...
    
            'Add Context menu:
            Dim menu As New ContextMenuStrip()
            Dim t As ToolStripItem = menu.Items.Add("Item 1")
            AddHandler t.Click, AddressOf menuItem1_Click
            t = menu.Items.Add("Item 2")
            AddHandler t.Click, AddressOf menuItem2_Click
            t = menu.Items.Add("Item 3")
            AddHandler t.Click, AddressOf menuItem3_Click
    
            childGrid.ContextMenuStrip = menu
    
          End If
        End If
    
      End Sub
    
    

    In a click handler, I can fetch the current grid (and any data from the grid) with this code:

    
      Private Sub menuItem1_Click(sender As Object, e As EventArgs)
    
        Dim menuItem As ToolStripMenuItem = CType(sender, ToolStripMenuItem)
        'Get the context menu
        Dim menuStrip As ContextMenuStrip = CType(menuItem.Owner, ContextMenuStrip)
        'Get the C1FlexDataTree that owns the context menu
        Dim childGrid As C1FlexDataTree = CType(menuStrip.SourceControl, C1FlexDataTree)
    
        Dim message As String = "Level: " + childGrid.level.ToString()
    
        message += ", Data: " + childGrid(childGrid.Row, 1).ToString()
    
        MsgBox("Item 1 clicked: " + message)
    
      End Sub
    
    

    DataTree_ContextMenu.zip

    Does this help?

    Wolfgang

Need extra support?

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

Learn More

Forum Channels