Click here to Skip to main content
15,887,214 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
Hello
VB NET , I have Tree View accounts arranged according to the main account and under it children and it works perfectly
How can the tree be displayed the same way but in a datagridview I just want the arrangement and I don't want the properties of the tree I want to arrange the children under the parents
Thank you in advance


What I have tried:

Dim COUNT_ As Integer = 0
           Dim DT, DT2 As New DataTable
           DT.Clear()
           DT2.Clear()
           DT = CLS_ACCOUNT_.SHOW_
           DGV.RowCount = DT.Rows.Count + 1
           For I As Integer = 0 To DT.Rows.Count - 1
               DT2 = CLS_ACCOUNT_.SHOW_PARENTGUID(DGV.Rows(COUNT_).Cells(0).Value)

               DGV.Rows(COUNT_).Cells(0).Value = DT.Rows(I)(2).ToString
               DGV.Rows(COUNT_).Cells(1).Value = DT.Rows(I)(3).ToString
               DGV.Rows(COUNT_).Cells(2).Value = DT.Rows(I)(1).ToString

               For J As Integer = 0 To DGV.Rows.Count - 1

                   If DT2.Rows.Count > 0 Then
                       DGV.Rows.Add()
                       DGV.Rows(COUNT_).Cells(0).Value = DT2.Rows(I)(0).ToString
                       DGV.Rows(COUNT_).Cells(1).Value = DT2.Rows(I)(3).ToString
                       DGV.Rows(COUNT_).Cells(2).Value = DT2.Rows(I)(1).ToString
                       'Else

                   End If

               Next
               COUNT_ += 1
           Next
Posted
Updated 20-May-23 5:32am

1 solution

There are multiple app platforms - WinForms, WPF, Asp.Net, MCV, Blazor, MAUI, etc... It's always good to be specific to which app platform that you are working with. In saying that, at a guess, based on your code and that it VB, I would guess that this is a WinForms question.

The answer therefore, is not possible with out-of-the-box controls. This may sound simple but is a compound control.

You would need to use a 3rd-party control. A quick google search: winform tree grid - Google Search[^] turned up this: Free or open source Tree-grid for C#? [closed][^] which points to this: ObjectListView — ObjectListView 2.9.1 documentation[^]

Here is another Google Search that is more targeted to what you are looking for: winform TreeListView - Google Search[^] ... gives lots of choices...
 
Share this answer
 
v2

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900