Go Premium for a chance to win a PS4. Enter to Win

x
  • Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 170
  • Last Modified:

Query builder with data control



I will have a listbox or some other control that will have all the fields of a query.  I want the users to be able to choose the fields they want, then those fields will be the fields in the dbgrid1.  

In other words, if query 1 has 40 fields and the user chooses only 3 from the listbox then dbgrid1 will have only those 3 fields.  I don't want the DBGrid to show blank columns.  I need good instructions on how to do this.  

Please leave a message if you need clarification.
0
DAVIDH
Asked:
DAVIDH
  • 3
  • 3
  • 2
  • +1
1 Solution
 
a111a111a111Commented:
If you need more help email to shay@hili.com

Private Sub cmdFillDbGrid_Click()
MSFlexGrid1.Rows = 8    ' Set rows and columns.
MSFlexGrid1.Cols = 5

'MSFlexGrid1.Text = "There"

For I = 0 To 3
    For J = 0 To List1(I).ListCount - 1
        If List1(I).Selected(J) Then
            MSFlexGrid1.Col = 0
            MSFlexGrid1.Row = J
            MSFlexGrid1.Text = I & J
        End If
    Next J
Next I

End Sub

0
 
a111a111a111Commented:
I have use MSFlexGrid instad of DbGrid.
This works.
0
 
a111a111a111Commented:
Correction.

Private Sub cmdFillDbGrid_Click()
MSFlexGrid1.Rows = 6
MSFlexGrid1.Cols = 5
Dim CountRow

For I = 0 To 3
    For J = 0 To List1(I).ListCount - 1
        If List1(I).Selected(J) Then
            MSFlexGrid1.Col = 0
            CountRow = CountRow + 1
            MSFlexGrid1.Row = CountRow  '*** just the selected will be on the grid.
            MSFlexGrid1.Text = I & J
        End If
    Next J
Next I

End Sub

0
Concerto Cloud for Software Providers & ISVs

Can Concerto Cloud Services help you focus on evolving your application offerings, while delivering the best cloud experience to your customers? From DevOps to revenue models and customer support, the answer is yes!

Learn how Concerto can help you.

 
DAVIDHAuthor Commented:
I do appreciate your response, but it still doesn't work i get the same error message.  What I am looking for:

lets say I have 7 items in a list box.  I want the dbgrid or msflexgrid to only show those 7 items (the dbgrid is tied to an access table the access table may have 30 fields, I only want the fields in the listbox)

thanks
0
 
nbishopCommented:
Simply use the visible property for each column in the grid you want (or don't want) displayed.
0
 
DAVIDHAuthor Commented:
Thanks for the suggestion, but my problem is, I have to do this at run time, The user is going to select certain fields, it has to be automatic.  If you have a sample of how to do this at runtime let me know.

Thanks
0
 
mcixCommented:
As nbishop suggested, you can accomplish the desired result by using the visible property of the column object...

This ONLY works with a DBGrid and has a limitation!

Private Sub cmdSetVisibleInGrid_Click()
' Where lstQueryFields = Your List Box with the Field Names
' And dbgData = Your DBGrid
' Using this code, the Index of each Item in the list box
' would have to match the Column Number in the DBGrid

Dim mlngCurrentListEntry As Long

    For mlngCurrentListEntry = 0 To lstQueryFields.ListCount - 1
        If lstQueryFields.Selected(mlngCurrentListEntry) Then
            dbgData.Columns(mlngCurrentListEntry).Visible = True
        Else
            dbgData.Columns(mlngCurrentListEntry).Visible = False
        End If
    Next
   
End Sub
0
 
mcixCommented:
I failed to mention that you should have Multi-Select set to true for the ListBox control...

But you probably already knew that.
0
 
nbishopCommented:
In an effort to redeem myself, here is a very brief snippet of code to place in the...doubleClick section?...of your list control.  I will dynamically remove colums from the grid with the same name as the columns in the list control.  The caption property of the grid (DBGrid) is case sensitive, so you should use some function like UCase to get around that.  I have not tried this with TrueGrid, but I would imagine that the same should work.  Hope this helps.

    Dim c As Column
    For Each c In DBGrid1.Columns
        If List1.List(List1.ListIndex) = c.Caption Then
        c.Visible = False
        End If
    Next
0
 
nbishopCommented:
In an effort to redeem myself, here is a very brief snippet of code to place in the...doubleClick section?...of your list control.  I will dynamically remove colums from the grid with the same name as the columns in the list control.  The caption property of the grid (DBGrid) is case sensitive, so you should use some function like UCase to get around that.  I have not tried this with TrueGrid, but I would imagine that the same should work.  Hope this helps.

    Dim c As Column
    For Each c In DBGrid1.Columns
        If List1.List(List1.ListIndex) = c.Caption Then
        c.Visible = False
        End If
    Next
0

Featured Post

Industry Leaders: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

  • 3
  • 3
  • 2
  • +1
Tackle projects and never again get stuck behind a technical roadblock.
Join Now