Solved

Datagrid Control - Error: The current row is not available

Posted on 2004-04-29
1
1,170 Views
Last Modified: 2013-12-25
Hello,
       I have a couple of questions....
       1) I am using a Datagrid Control which is populated from a database. When i close the form i get an Error - "The current row is not available". The datagrid control is not editable. When i debug through the form, i do not get this error or when the entire row is selected.
       2) I want to be able to select an entire row when clicking on any field. Is this possible?

Thank you for your help.
0
Comment
Question by:ppseeth
1 Comment
 
LVL 69

Accepted Solution

by:
Éric Moreau earned 125 total points
ID: 10955751
1) http://www.experts-exchange.com/Programming/Programming_Languages/Visual_Basic/Q_20749316.html

2) Here is the required code for that:

Option Explicit

Dim rstX As ADODB.Recordset

Private Sub DataGrid1_RowColChange(LastRow As Variant, ByVal LastCol As Integer)
    With DataGrid1
        ' Remove previously saved bookmark from collection
        If .SelBookmarks.Count <> 0 Then .SelBookmarks.Remove 0
        ' Append your bookmark to the collection of selected rows
        If Not IsNull(.Bookmark) Then .SelBookmarks.Add .Bookmark
    End With
End Sub

Private Sub Form_Load()
Dim colX As Variant

    Set rstX = New ADODB.Recordset
    rstX.CursorLocation = adUseClient
    rstX.Open "Select * from Employees", "Provider=Microsoft.Jet.OLEDB.4.0;Data Source=C:\Projets VB\NWIND.MDB;Persist Security Info=False", adOpenStatic, adLockReadOnly
    Set DataGrid1.DataSource = rstX
    DataGrid1.Refresh
    For Each colX In DataGrid1.Columns
        colX.Locked = True
    Next
End Sub

0

Featured Post

Is Your Active Directory as Secure as You Think?

More than 75% of all records are compromised because of the loss or theft of a privileged credential. Experts have been exploring Active Directory infrastructure to identify key threats and establish best practices for keeping data safe. Attend this month’s webinar to learn more.

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Most everyone who has done any programming in VB6 knows that you can do something in code like Debug.Print MyVar and that when the program runs from the IDE, the value of MyVar will be displayed in the Immediate Window. Less well known is Debug.Asse…
This article describes some techniques which will make your VBA or Visual Basic Classic code easier to understand and maintain, whether by you, your replacement, or another Experts-Exchange expert.
As developers, we are not limited to the functions provided by the VBA language. In addition, we can call the functions that are part of the Windows operating system. These functions are part of the Windows API (Application Programming Interface). U…
Get people started with the process of using Access VBA to control Excel using automation, Microsoft Access can control other applications. An example is the ability to programmatically talk to Excel. Using automation, an Access application can laun…

912 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question

Need Help in Real-Time?

Connect with top rated Experts

17 Experts available now in Live!

Get 1:1 Help Now