Quantcast
Channel: VBForums - Visual Basic 6 and Earlier
Viewing all articles
Browse latest Browse all 21842

[RESOLVED] How to highlight a row using datagrid in visual basic 6?

$
0
0
Hello everyone,

I have a problem here about the highlighting of the whole row programmatically (not by just clicking the row in the left side of the grid).
I've thought the setfocus property would help but that doesn't work. So, is it possible to highlight the whole row programmatically?

I want to make a program that when i clicked the search button, it will highlight the whole row of the datagrid that matches of what i'm searching.

I tried to search on google, and I found this code:

Code:

Option Explicit

      Dim cn As New ADODB.Connection
      Dim rs As New ADODB.Recordset
      Dim cmd As New ADODB.Command
      Dim i As Integer
      Dim FindLastName As String

      Private Sub Command1_Click()

        ' Remove previously saved bookmark from collection
        If (DataGrid1.SelBookmarks.Count <> 0) Then
            DataGrid1.SelBookmarks.Remove 0
        End If

        ' Prompt user for desired author's last name
        FindLastName = InputBox("Please enter the author's last name you
                                  want to search for", "Find")

        rs.Find "au_lname = '" & FindLastName & "'", , , 1

        ' Append your bookmark to the collection of selected rows
        DataGrid1.SelBookmarks.Add rs.Bookmark

      End Sub

      Private Sub Form_Load()

        ' Open your ADO connection where "Pubs" is an ODBC DSN that
        ' points to pubs database in SQL Server
        cn.Open "Pubs"

        ' Create your command to query for all records in Authors table
        With cmd
            .ActiveConnection = cn
            .CommandText = "select * from authors"
        End With

        ' Open your recordset
        With rs
            ' Set rs properties
            .CursorType = adOpenKeyset
            .LockType = adLockOptimistic

            ' Call open using active command
            .Open cmd
        End With

        ' Populate the DataGrid providing rs as the data source
        Set DataGrid1.DataSource = rs

      End Sub

But then I realized that in this example, you have to use the sql server as your database.
I'm just using MSACCESS as my database.
I just want to know also if the code above really works on highlighting the row.

BTW, i found the code here http://support.microsoft.com/kb/195472

TIA :D

Viewing all articles
Browse latest Browse all 21842

Trending Articles



<script src="https://jsc.adskeeper.com/r/s/rssing.com.1596347.js" async> </script>