Why Experts Exchange?

Experts Exchange always has the answer, or at the least points me in the correct direction! It is like having another employee that is extremely experienced.

Jim Murphy
Programmer at Smart IT Solutions

When asked, what has been your best career decision?

Deciding to stick with EE.

Mohamed Asif
Technical Department Head

Being involved with EE helped me to grow personally and professionally.

Carl Webster
CTP, Sr Infrastructure Consultant
Ask ANY Question

Connect with Certified Experts to gain insight and support on specific technology challenges including:

Professional Opinions
Ask a Question
Did You Know?

We've partnered with two important charities to provide clean water and computer science education to those who need it most. READ MORE

troubleshooting Question

VSFlexGrid 8: Create a "sub-grid" inside existing grid control.

Avatar of khufford19
khufford19Flag for United States of America asked on
Visual Basic Classic
2 Comments1 Solution1463 ViewsLast Modified:
Hello, again. For any of you that are using Component One's VSFlexGrid control, I'm wondering if it's possible to somehow create a second grid inside of an existing FlexGrid control. Here's the scoop:

I have a FlexGrid control in my Windows application that contains a row of data. The data in this row is related to even more data that won't all fit on the same row. For Example:

The main data row contains Username, Last Name, First Name, Middle Name, E-mail Address, Phone Number, etc.

A secondary row to this might contain user permissions to certain resources, such as File Server Access, FTP Access, Remote Access, etc.

Now, I can use the subtotal and outline capabilities of the VSFlexGrid to make a second row, but the column widths are still bound by those set for the main data row. Additionally, I can't put real "headers" on the supplemental data. I have to fake it by creating an additional row, setting the background color of that row to gray, putting the header strings into those fields, and then adding the next row with the actual details.

What I would like to do is create separate grids for these secondary rows and "embed" them in a blank row of the existing FlexGrid control directly under the related main data row. This would give me the ability to use a different number of columns, to format these columns independently of the "parent" FlexGrid settings, as well as put a new header row for the new grid that identifies its data.

In other words, I'd like to somehow make a "child" grid that's related to a particular row of the "parent" grid (not the entire grid itself). I don't know if this is possible, and if there is another way for me to accomplish this goal, I'm all ears. However, if it IS possible, I'd love some advice on how to implement it.  I've been scouring forum posts and such, but can't seem to find a viable solution for making this work the way I want. I almost hate to make the reference here, but I want it to work kinda the same way as MS Access does when you have linked tables - the linked data pops up underneath the "source" data in a grid of its own when the user clicks the "+" sign to expand the row. Of course, I want to have everything already expanded so the user doesn't have to click the "+", but it's the same basic concept.

So, here's what I've tried so far:

I know I'll need to create a new grid object for each row, so in my loop, after I create the primary data row, I setup an entirely new grid. However, the problem comes in trying to put the grid in position as a sort of "subtotal" row to my primary data row.

I tried setting the .Parent property of the new grid to the source grid (detailGrid.Parent = myGrid), but that just results in my new grid overlapping the entire originating grid. However, I think that I'm kinda on the right track with the .Parent property.

I tried to add a blank row to the end of the main grid, and then convert that row to a control (CType(myGrid.Rows - 1, Control)). Of course, that specific code doesn't work (can't convert an Integer to a Control), but I can't seem to find the right property or function to use here. I've tried several different ways of making this happen, but I can't seem to get it right.

I've put the code (specific data details altered) below. The data is pulled from a DataTable I'm filling with a SQL query that joins multiple database tables. If anyone has any ideas, I'd REALLY appreciate it. My head's starting to get a little sore from banging against the wall on this one.  Maybe another grid control (like the MS FlexGrid control) is the way to go, but I really like the functionality and usability of the VSFlexGrid - with this one notable exception, of course. ;-)

Oh, BTW, I'm using Visual Basic 2005 with VSFlex8.dll in the project reference.  Any help would be greatly appreciated.  Thank you so much for your time.
Public Sub PopulateUserGrid(ByVal myGrid As AxVSFlexGrid)
        Dim I As Integer
        Dim strRow As String = vbNullString
            myGrid.Rows = 1
            myGrid.Cols = 7
            myGrid.FixedCols = 1
            myGrid.FixedRows = 1
            myGrid.Select(0, 0, myGrid.Rows - 1, myGrid.Cols - 1)
            myGrid.set_TextMatrix(0, 0, "USERNAME")
            myGrid.set_TextMatrix(0, 1, "LAST NAME")
            myGrid.set_TextMatrix(0, 2, "FIRST NAME")
            myGrid.set_TextMatrix(0, 3, "MIDDLE NAME")
            myGrid.set_TextMatrix(0, 4, "E-MAIL ADDRESS")
            myGrid.set_TextMatrix(0, 5, "PHONE #")
            myGrid.Redraw = VSFlex8.RedrawSettings.flexRDNone
            If Not Users.Rows.Count < 1 Then
                For I = 0 To Users.Rows.Count - 1
                    strRow = Users.Rows(I).Item("UserID").ToString & vbTab
                    If Not IsDBNull(Users.Rows(I).Item("LName")) And _
                        Len(Trim(Users.Rows(I).Item("LName").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("LName").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("FName")) And _
                        Len(Trim(Users.Rows(I).Item("FName").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("FName").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("MName")) And _
                        Len(Trim(Users.Rows(I).Item("MName").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("MName").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("EMail")) And _
                        Len(Trim(Users.Rows(I).Item("EMail").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("EMail").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("Phone")) And _
                        Len(Trim(Users.Rows(I).Item("Phone").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("Phone").ToString)
                        strRow = strRow & ""
                    End If
                    strRow = vbNullString
                    myGrid.set_IsSubtotal(myGrid.Rows - 1, True)
                    myGrid.Rows = myGrid.Rows + 1
                    Dim detailGrid As New AxVSFlexGrid
                    detailGrid.Name = detailGrid.Name & CStr(I)
                    detailGrid.Parent = myGrid
                    detailGrid.Rows = 1
                    detailGrid.Cols = 5
                    detailGrid.FixedCols = 0
                    detailGrid.FixedRows = 1
                    detailGrid.Select(0, 0, detailGrid.Rows - 1, detailGrid.Cols - 1)
                    detailGrid.set_TextMatrix(detailGrid.Rows - 1, 0, "Files?")
                    detailGrid.set_TextMatrix(detailGrid.Rows - 1, 1, "FTP?")
                    detailGrid.set_TextMatrix(detailGrid.Rows - 1, 2, "Remote?")
                    detailGrid.set_TextMatrix(detailGrid.Rows - 1, 3, "SQL?")
                    detailGrid.set_TextMatrix(detailGrid.Rows - 1, 4, "Web?")
                    If Not IsDBNull(Users.Rows(I).Item("FileServerAccess")) And _
                        Len(Trim(Users.Rows(I).Item("FileServerAccess").ToString)) > 0 Then
                        strRow = vbTab & Trim(Users.Rows(I).Item("FileServerAccess").ToString) & vbTab
                        strRow = vbTab & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("FTPUser")) And _
                        Len(Trim(Users.Rows(I).Item("FTPUser").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("FTPUser").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("RemoteAccess")) And _
                        Len(Trim(Users.Rows(I).Item("RemoteAccess").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("RemoteAccess").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("SQLServer")) And _
                        Len(Trim(Users.Rows(I).Item("SQLServer").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("SQLServer").ToString) & vbTab
                        strRow = strRow & "" & vbTab
                    End If
                    If Not IsDBNull(Users.Rows(I).Item("WebUser")) And _
                        Len(Trim(Users.Rows(I).Item("WebUser").ToString)) > 0 Then
                        strRow = strRow & Trim(Users.Rows(I).Item("WebUser").ToString)
                        strRow = strRow & ""
                    End If
                    strRow = vbNullString
                Next I
                strRow = "NO ADDITIONAL DETAILS AVAILABLE FOR " & UserNumber
                strRow = vbNullString
            End If
            myGrid.Redraw = VSFlex8.RedrawSettings.flexRDDirect
        Catch ex As Exception
        End Try
    End Sub
Avatar of khufford19
khufford19Flag of United States of America image

Our community of experts have been thoroughly vetted for their expertise and industry experience.

This problem has been solved!
Unlock 1 Answer and 2 Comments.
See Answers