populate a datagrid from a text box search.
CodeGuru Home VC++ / MFC / C++ .NET / C# Visual Basic VB Forums Developer.com
Results 1 to 12 of 12

Thread: populate a datagrid from a text box search.

  1. #1
    Join Date
    May 2008
    Posts
    18

    populate a datagrid from a text box search.

    I have no prior c++ programming experience only vbscript in asp pages, sorry to say.
    Here is what I am trying to accomplish:
    A user types in a text box (txtSearch) and then clicks a button (cmdSearch).
    From there I would like the results returned to a datagrid (DataGrid1).

    I'm using Visual C++ 6 and an access database.

    I can make the skeleton of the program in Visual C++ rather easily, though I can't seem to find a datagrid control.
    Could someone assist me in this?

    I really want to learn how to do this.

  2. #2
    VictorN's Avatar
    VictorN is offline Super Moderator Power Poster
    Join Date
    Jan 2003
    Location
    Wallisellen (ZH), Switzerland
    Posts
    17,274

    Re: populate a datagrid from a text box search.

    Quote Originally Posted by XandarX
    ... I would like the results returned to a datagrid (DataGrid1).

    I'm using Visual C++ 6 and an access database.
    ...
    I can't seem to find a datagrid control.
    So where and how did you try to look for "datagrid control"?
    And what in this case does the DataGrid1 mean?

    Have you tried to find something useful going into Menu Project -> Add to Project -> Components and Controls -> Registered ActiveX Controls -> choose something like "DBGrid Control" or "Microsoft DataGrid Control 6.0 (SP6) (OLEDB)" or something else... (I don't know what you need and never used any grid control at all - for my purposes using the "common" ListView control was pretty good and enough)
    Victor Nijegorodov

  3. #3
    Join Date
    Feb 2002
    Posts
    3,788

    Re: populate a datagrid from a text box search.

    Quote Originally Posted by VictorN
    (I don't know what you need and never used any grid control at all - for my purposes using the "common" ListView control was pretty good and enough)
    most likely because the OP has previous VB experience and grids are really common in VB.

  4. #4
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    got that part worked out. the control wasn't registered. found it and now it's on my form.
    DataGrid1 is the name of the datagrid control on my form.

    I need to populate it with information from an access database based on a sql query performed when the button is pressed.

  5. #5
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    what is an "OP"?

  6. #6
    GCDEF is offline Elite Member Power Poster
    Join Date
    Nov 2003
    Posts
    12,047

    Re: populate a datagrid from a text box search.

    Quote Originally Posted by XandarX
    what is an "OP"?
    Original Poster - the person who started the thread.

  7. #7
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    The problem is that I have an access database and I need to display 5 fields from it after searching based on input criteria.
    Datagrid is the only way I know of to accomplish this. Is there another way?

  8. #8
    Join Date
    Feb 2002
    Posts
    3,788

    Re: populate a datagrid from a text box search.

    Quote Originally Posted by XandarX
    The problem is that I have an access database and I need to display 5 fields from it after searching based on input criteria.
    Datagrid is the only way I know of to accomplish this. Is there another way?
    CListControl should more than provide you with the functionality you are after.

  9. #9
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    This is what I eventually came up with, and it works, except one point that I cannot seem to grasp. It will only return results from the first field in the database, nothing from the others. Can someone tell me what is wrong with my search query?


    Private Sub Form_Load()

    Data1.DatabaseName = "C:\db3.mdb"
    MSFlexGrid1.Visible = False
    MSFlexGrid1.Cols = 4
    MSFlexGrid1.ColWidth(0) = 2000
    MSFlexGrid1.ColWidth(1) = 2000
    MSFlexGrid1.ColWidth(2) = 4000
    MSFlexGrid1.ColWidth(3) = 2000

    With Me.MSFlexGrid1
    .Row = 0
    .Text = "Title"
    .Col = 1
    .Text = "Artist"
    .Col = 2
    .Text = "Description"
    .Col = 3
    .Text = "DiscNo"
    End With
    End Sub

    Private Sub Command1_Click()
    On Error GoTo BADSTRING
    Dim My_Query As String
    MSFlexGrid1.Visible = True

    Data1.RecordSource = "SELECT * FROM Lu2 WHERE Title LIKE '" & Text1.Text & "' OR Artist LIKE '" & Text1.Text & "' OR Description LIKE '" & Text1.Text & "' OR DiscNo LIKE '" & Text1.Text & "'"

    Data1.Refresh

    Data1.Recordset.MoveFirst
    MSFlexGrid1.Cols = Data1.Recordset.Fields.Count - 2
    Do While Not Data1.Recordset.EOF
    MSFlexGrid1.AddItem Data1.Recordset(1) & vbTab & Data1.Recordset(2) & vbTab & Data1.Recordset(3) & vbTab & Data1.Recordset(4)
    Data1.Recordset.MoveNext
    Loop

    Exit Sub
    BADSTRING:
    MSFlexGrid1.Visible = False
    MsgBox "No Records Found"
    End Sub

  10. #10
    Join Date
    Oct 1999
    Location
    ks
    Posts
    502

    Re: populate a datagrid from a text box search.

    the msflexgird is also a fairly nice choice available in vc++6.0. just for s&g does anybody know what they did with msflexgrid in vc++7.0(?) that comes in vs2005? this has been driving me nuts.

  11. #11
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    Try adding it to your toolbox. It should be listed under Com Components. Assuming you have upgraded your vc++? If you never had it on that machine I do not know that it is available with the installation. I think it's an ocx file, may be able to load it. msflxgrd.ocx

  12. #12
    Join Date
    May 2008
    Posts
    18

    Re: populate a datagrid from a text box search.

    I just realized that I switched from vc++ to vb. I'm in the wrong forum.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  


Azure Activities Information Page

Windows Mobile Development Center


Click Here to Expand Forum to Full Width

This is a CodeGuru survey question.


Featured


HTML5 Development Center