-
Aug 8th, 2020, 12:27 PM
#1
Thread Starter
Junior Member
How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Hello, I have a DataGrid1 hooked up to adodc1, and an access file connected with adodc1 through settings (not code). The problem is when I delete a row from the middle of DataGrid1 using a DblClick on that row .. the row goes away just fine -which is what I want-, but when I hit the CmdLog button to log a new entry from the end of the DataGrid .. all rows after where the DblClick was disappear. My database is Access 2003, and I am working on VB6.
Two Questions:
1- How to delete a row from the middle of the DataGrid1, and get the rows before & after it stitched together?
2- Is there a way to make the data saved all at once upon an event i.e., button click or closing the program?
Here is my code
Code:
Private Sub DataGrid1_DblClick()
On Error GoTo Rora
DataGrid1.Refresh
Adodc1.Recordset.Delete
Adodc1.Refresh
Adodc1.Recordset.Update
'Adodc1.Recordset.Refresh
Rora:
Exit Sub
End Sub
Private Sub CmdLog_Click()
Adodc1.Refresh
Adodc1.Recordset.AddNew
DataGrid1.Columns(0) = Variable
DataGrid1.Columns(1) = Variable1
DataGrid1.Columns(2) = Variable2
DataGrid1.Columns(3) = Variable3
DataGrid1.Columns(4) = Variable4
DataGrid1.Columns(5) = Variable5
DataGrid1.Columns(6) = Variable6
Adodc1.Recordset.MoveLast
End Sub
-
Aug 10th, 2020, 03:57 AM
#2
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Moved to VB6 as this isn't really a DB question. You're likely to get better answers here.
The best argument against democracy is a five minute conversation with the average voter - Winston Churchill
Hadoop actually sounds more like the way they greet each other in Yorkshire - Inferrd
-
Aug 10th, 2020, 07:19 AM
#3
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
It should be as simple as just deleting the record.
What service pack do you have installed? You should be running SP6 if you have no SP installed perhaps that could be your problem. I personally do not use the adodc in part because early on there was a bug that caused a problem when it was bound to a grid. The bug was fixed in an early service pack but I never went back to using it as I like the control I get from using straight up code instead.
-
Aug 13th, 2020, 04:46 PM
#4
Thread Starter
Junior Member
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
I have no service pack installed, but I just downloaded service pack 6 from Microsoft's website; it seems like the extracted files don't run in any folder. What folder should I extract them into?
If a grid can be saved without the use of adodc that would be great! Can it?
Last edited by SaudVb; Aug 13th, 2020 at 05:18 PM.
-
Aug 13th, 2020, 05:39 PM
#5
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Link:
https://www.microsoft.com/en-us/down...s.aspx?id=5721
Installation Instructions:
Before starting the download, create a download directory on your computer. If your internet connection is less than 300K, it is recommended that you run the multi-part download by following the "More Information" link at the upper right, then clicking "Download Now."
Click "Download" to begin downloading the single download. When prompted by the download software, choose the option "Save this program to disk" and click OK. Then select the directory you created on your computer.
Run the file from the download directory. When prompted, select the same directory you created on your computer. You will be expanding the contents of the EXE into this directory.
Run SetupSP6.exe from the download directory. When you accept the terms of the electronic End User License Agreement (EULA) the setup software will replace the appropriate files in your Visual Basic 6.0 installation.
-
Aug 13th, 2020, 05:44 PM
#6
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Trying to fight with the DataGrid in code isn't the best option. It already supports row-deletion:
Data
Row Selector clicked
DELete key pressed, deleting the row
-
Aug 13th, 2020, 06:02 PM
#7
Thread Starter
Junior Member
-
Aug 13th, 2020, 06:08 PM
#8
Thread Starter
Junior Member
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Mr. dilettante,
Very good, thank you. But The issue isn't about the ability to delete; the issue is when you delete a row then insert a new row, all rows get deleted except for the top one.
Last edited by SaudVb; Aug 13th, 2020 at 06:28 PM.
-
Aug 13th, 2020, 06:47 PM
#9
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
To use a code based RS rather than the adodc you have to create a rs and bind the grid to it.
There is a handy dandy little data form wizard in VB that will create a basic data form for you. You can choose to use datagrid there and you can choose control, code or class. When you choose code it will create a few routines that open the selected table and bind it to the grid, also will add code for adding, deleting and other stuff. It is far from perfect but it can give you an idea of how to do this through code.
To use the data form wizard just go to project/add form and select the data form wizard from the list of templates that show up.
-
Aug 13th, 2020, 06:59 PM
#10
Thread Starter
Junior Member
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
DataMiser,
You're right, I learned this from "brucevde" https://www.vbforums.com/showthread....30#post5489430
But it would be great to also learn how to save this coded grid so the user doesn't lose his data after restarting the app. Whether to save within the app or as an export/import file .. doesn't matter.
Last edited by SaudVb; Aug 13th, 2020 at 07:03 PM.
-
Aug 13th, 2020, 07:04 PM
#11
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Originally Posted by SaudVb
Are you talking about the in memory recordset from that thread? Not sure what you are trying to do or ask at this point.
The dataform wizard approach uses a db. It is simple enough to write something to an ini file so that you can pick up in the same spot the next time the user runs the app if you want. As for an in memory rs well first you have to save the rs to disk then you would have to reload it when the run the program again. Definitely can be done but makes a lot more sense to use a database.
-
Aug 13th, 2020, 07:04 PM
#12
Re: How to Delete a DataGrid1 Row Without Deleting All the Rows After? VB6
Here I have entered Row 1, Row 2, Row 3, and Row 4. Then I deleted Row 2. Finally I added New Row:
In this case I have also formatted the "Price" column in the DataGrid, as well as hiding the Id column:
Code:
Private Sub Form_Load()
Dim Fmt As StdFormat.StdDataFormat
Set Fmt = New StdFormat.StdDataFormat
With Fmt
.Type = fmtCustom
.Format = "$#0.00"
.NullValue = vbNullString
End With
With DataGrid1
.WrapCellPointer = True
.TabAction = dbgGridNavigation
.Columns("Id").Visible = False
Set .Columns("Price").DataFormat = Fmt
End With
End Sub
So I don't see the problem. Most likely you have broken something in code (probably fiddling with DataGrid1.Recordset in code, always a bad idea).
Don't use the old ADODC at all. As I said in another thread, the DataEnvironment replaced it in 1998 and is far more powerful and flexible anyway. But even if you insist on using the clunky old ADODC it should not be broken enough to cause the problem you are seeing.
Tags for this Thread
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|