Hi everyone, I have been using S Grid in my app and its been working great. Now I am trying to do something though I havent done before with SGrid, editing the cells. In the new grid I have created I have 2 columns. One column shows the titles/captions and the other is all the cells that I want to editable. I set the grid Editable property to true and I have the following code:
VB Code:
Private Sub DetailsGrid_SelectionChange(ByVal lRow As Long, ByVal lCol As Long)
If lCol = 2 Then
DetailsGrid.StartEdit(lRow, lCol) = True
End If
End Sub
When I run the project and if I click anywhere on the grid I get the following error: "Assignment to constant not permitted"..
Any Suggestions?? Thanx everyone for the help!
I am thinking it probably isnt having to really do with editing SGrid because if I put a watch on lCol, lCol doenst equal anything, it states <Can't Compile Module> in as the value.
I will glance at the example thanx for that. But lCol should be giving me a value...I dont see why it isnt. If it was to give me a value I am sure it would work. Here is a link to their site about the different edit properties. They do mention the Request Edit event but they dont explain anything about it..
My memory ain't what it used to be, so this may be incorrect.
I have a vague recollection of using a similar event to yours in some other grid, and was getting thwarted by some col or row value not updating until a bit later in the event sequence.
All you will need to get the Edit Example zip above, working is this other attachment -
Install_SGrid2_and_ImageList_Unzip_Me_and_run_Setup_exe.zip
If you go to this link and look down near the bottom, you will find that zip file. Re SGrid Help
(The attachment is about 8 post up from the bottom)
It installs a couple of controls, and a DLL (SSubTmr6.dll) that you can read up on at the VBAccelerator web site.
The example should then run easily on your system.
I also use that installer on my clients computers.
I don't install my programs (they use only a couple of controls), I just give them the exe.
When I decided to use the SGRid2, I created that stand alone installer, which I run once only on their computers.
The sequence of events that works for me, is the following...
With an SGrid called Grid1 and a text box called txtEdit and
VB Code:
Grid1.Editable = true
1. Code request an edit of a row and a column using
VB Code:
Grid1.StartEdit mNextRowToEdit, mNextColToEdit
When Grid1_RequestEdit fires (this code section is available directly in the demo code that comes with the grid) it positions the text box over the cell (this may need the odd tweak if you are resizing your grid) and makes it visible.
2. The user enters the text value for the new grid cell and hits enter.
3. txtEdit_Keypress is firing all the time that text is being added to the txtbox, but the procedure only really needs to respond to the keyAscii value of 13. At this point the second thing you do in the txtEdit_Keypress event is end the editing session with
VB Code:
Grid1.Endedit = true
This is necessary, because unless you do this ( as you will see later) the cell edit will NOT refire.
4. Grid1_PreCanceledit is called (because you have ended the edit in (3)) and it is here you evaluate the text that has been entered in the text box. If you are happy with it you ..
a. Update the grid with the new value
b. Stash the new value into you program somewhere, If the grid is fronting a database then you need to do an SQL to update your base records.
Cancel edit fires and the text box becomes hidden.
If you are unhappy with what has been entered into the text box set the variable
VB Code:
bStayInEditMode = True
The Cancel is itself Cancelled and crutially the texEdit text box is left visible.
5. Picking up in (3) again. The events of 4 kick off when you call the line
VB Code:
Grid1.Endedit = true
immediately after this line you can make the decision.
VB Code:
If txtEdit.Visible = False then
'Point to the next cell you want to edit (normally the one below, but you could go to the next column)
....
....
Grid1.StartEdit mNextRowToEdit, mNextColToEdit ' Starts it all again
Else
' You are still editing the same cell. Bring up an error message here if you like.
' Something along the lines of " Numeric data only please"
Endif
And that as they say in the trade is that.
HTH
David
Learn the Rules so that you know how to break them properly.
Ok, I understand how editing works for S Grid now. =) Im still having the same problem though with the selection change event....any suggestions on how I can get it to work and why it isnt giving lCol or lRow a value? And is mNextRowToEdit, mNextColToEdit your own made up variables?
Ok, never mind, I guess putting "()" around lRow, lCol was producing the error...now I will try and get the editing part finished. Thank all for the help!