Tek-Tips is the largest IT community on the Internet today!

Members share and learn making Tek-Tips Forums the best source of peer-reviewed technical information on the Internet!

  • Congratulations bkrike on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Datagrid is 'Read-Only'

Status
Not open for further replies.

tekthis

MIS
Jun 9, 2004
77
US
i have a datagrid and a search function...when a user enters a search value the datagrid gets filled with data...i would like the user to be able to click on a cell in the datagrid and change info, but the datagrid spits out an error saying that it is "Read-Only"...how do i make it not read-only?...i cant find this topic in the FAQ section...thanks for your time...
 
Set the DataGrid properties:

DataGrid.AllowUpdate = True

and may be

DataGrid.AllowAddNew = True

Best regards
Hansu
 
ive tried those...this doesn't want to work when i perform a search...i have the datagrid set to a database prior to using the search and i am able to edit from that view...it only doesnt let me edit until after i search and those records pop up...thanks for your reply...
 
How did you set the datagrid to the database?
 
i set it up using the Adodc1...then i just set DataSource to that...then for my search function i open up the db again like this...
----------------------------------------------
Option Explicit
Dim Conn As ADODB.Connection 'Connection
Dim Rs As ADODB.Recordset 'Recordset
Dim strQuery As String 'Command

Private Const Test_Item As Integer = 5

Private Sub cmdSearch_Click()
Set Conn = New ADODB.Connection
With Conn
.CursorLocation = adUseClient
.ConnectionString = "Provider=Microsoft.Jet.OLEDB.4.0;" & _
"Data Source=C:\test\test.mdb"
.Open
End With

strQuery = "SELECT * FROM tblTest " & _
"WHERE UPC = '" & txtSearch.Text & "'"

Set Rs = New ADODB.Recordset
With Rs
Set .ActiveConnection = Conn
.CursorType = adOpenStatic
.Source = strQuery
.Open
End With
Set DataGrid1.DataSource = Rs
With DataGrid1
.Refresh
End With
If Not (Rs.BOF And Rs.EOF) Then
Do While Not Rs.EOF
DataGrid1.AllowUpdate = True
DataGrid1.AllowAddNew = True
DataGrid1.Columns(5).Locked = False
Rs.MoveNext
Loop
End If

End Sub

Private Sub cmdSet_Click()
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub
----------------------------------------------------
what im actually doing is opening the database as soon as the program is executed then when the user performs a search i re-open the db and populate it with the info...thanks again hansu...
 
Try to set the LockType property as well:

With Rs
Set .ActiveConnection = Conn
.CursorType = adOpenStatic
.LockType =adLockOptimistic
.Source = strQuery
.Open
End With


I don't see why you loop through rs to set the grid's properties?

You could just set:
With DataGrid1
.DataSource = Rs
.Refresh
End With
With DataGrid1
.AllowUpdate = True
.AllowAddNew = True
.Columns(5).Locked = False
End With

Regards
Hansu
 
.LockType = adLockOptimistic worked...thanks for your replies Hansu...i am getting one error when i try to close the database connection though...i close the connection with a button after i change a field...i do this beacuse the data gets deleted if i try to move in the grid...the error reads "error '3219' Operation in not allowed in this context"...debug points to Rs.Close...heres my function to close the connection...
---------------------------------------
Private Sub cmdSet_Click()
Rs.Close
Set Rs = Nothing
Conn.Close
Set Conn = Nothing
End Sub
---------------------------------------
thanks again...
 
Hey,
Try issuing rs.Update before trying to close.
Good Luck
 
...i do this beacuse the data gets deleted if i try to move in the grid... I am not quite sure what you mean by this. When you move to a different record (row) in the grid after data has been edited the data is moved to the data source. When the update is successful, the AfterUpdate event of the grid is fired and you should be able to close the rs and the connection without problems. So check whether that event is fired.

Regards Hansu
 
Forgot to mention:
When the user does not leave the current cell after editing the data before he clicks the cmdSet_Click button the editing progress is still pending and you can't close the rs.
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top