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 Mike Lewis on being selected by the Tek-Tips community for having the most helpful posts in the forums last week. Way to Go!

Deleting multiple records in a Datagrid 4

Status
Not open for further replies.

Sam8932

Programmer
Oct 15, 2002
22
0
0
Is this possible? Currently the user has to select one record at a time and delete it. This can sometimes be very time consuming as the user may have to delete many records. I'm using an ADO connection. If more info is needed please let me know. Thank you in advance.

Sam
 
Look into changing your Datagrid to a Flexgrid - you can do multiselect and more then. Let me know if this helps
________________________________________________________________
If you want to get the best response to a question, please check out FAQ222-2244 first

'People who live in windowed environments shouldn't cast pointers.'
 
Thanks johnwm. I'm able to select multiple records and delete them from the Hierarchical FlexGrid by using MSHFlexGrid1.RemoveItem i, but I need to also delete the records from the database. I'm not sure how to do this. Any suggestions? Thank you.

Sam
 
Hi, before executing RemoveItem, issue a delete on your database, using line info/id, as key.

Hope this help.
Carlos
 
>Look into changing your Datagrid to a Flexgrid - you can do multiselect and more then

You can do the same with a DataGrid as well.

You capture the Shift key in the KeyDown event to add a block of rows to the SelBookmark collection.
To mark multiple records not with-in a block you can use the grid's built-in function (Ctrl key and mouse click), which I believe the Flex Grid doesn't have.

Once rows are added to the SelBookmark collection, you only need to do a loop:

Do While DataGrid1.SelBookmarks.Count <> 0
rs.Bookmark = DataGrid1.SelBookmarks(0)
rs.Delete
DataGrid1.SelBookmarks.Remove 0
Loop
rs.MoveFirst

I only had to mention this here for the DataGrid users, just in case they may believe that it is not possible to block rows in a grid using the Shift key.
The DataGrid offers all the same functionality as the grid in the table view in the database window of MS Access.

The only real dis-advantage, with respect to basic usage, of the DataGrid vs. the FlexGrid is it's lack of being able to format individual cells with-in the same column, or indiviual rows, independently, with respect to color and font attributes. And then the HFlex grid has the Hierarchical capabilities. [/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
Thanks to all of you. You all have been very helpful. I got the FlexGrid to work. But CCLINT now has me interested in seeing if I can do it with a DataGrid. CCLINT can you you give me more info/code on how to do this? I'm not familiar with this event. Thanks again.

Sam
 
I've been off of this project, but I'm back on it now. I'm still hoping someone can tell me how to delete multiple rows with a datagrid. I've gotten this to work with the flexgrid, but this application is so big and complex that when I change the datagrid to a flexgrid it causes too many problems. Can someone please elaborate on what CClint said in the previous post so I can get this to work. Thank you in advance.

Sam
 
What exactly are you having problems with?

For instance: using Ctrl-A like in an Access table view.

In the KeyDown event capture the Ctrl and &quot;A&quot; key.
If these keys have been press (if you use the KeyDown event of the form and not the grid, you will need to also check if the ActiveControl is the Data Grid) then:

1. Loop through the Grid's bookmark collection and remove all items:
Do While .SelBookmark.Count <> 0
.SelBookmarks.Remove 0
Loop

2. Add all records from the recordset to the grid's bookmark collection:

If Not (rsAdo.Bof And rsAdo.Eof) Then

rsAdo.MoveFirst

For I = 0 To rsAdo.RecordCount- 1
DataGrid1.SelBookmarks.Add DataGrid1.Bookmark
rsAdo.MoveNext Next I

rsAdo.MoveFirst
DataGrid1.Row = 0
DataGrid1.SetFocus

End If

This will mark all the records in the grid.

Now, capture the delete key in the KeyDown event and use the code that I posted in my last post.

For using the Shift key and a mouse click, you need to perform a similar action, however, you will need to capture the currently selected row, and the one where the mouse is being click, then loop through the records between these two bookmarks.


Concerning the KeyDown event: Plenty of help in this forum on how to use it.

[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 

the line:

Do While .SelBookmark.Count <> 0

Should read:

Do While .SelBookmarks.Count <> 0
[/b][/i][/u][sub]*******************************************************
General remarks:
If this post contains any suggestions for the use or distribution of code, components or files of any sort, it is still your responsibility to assure that you have the proper license and distribution rights to do so!
 
I graduated last spring and I've only been programming in VB for a couple of months now. I had a class in college but never worked with grids this extensively. I don't understand what you mean when you say &quot;capture the key&quot;. I want to be able to allow the user to select multiple records in a datagrid by clicking on the grid and dragging and highlighting the records they want deleted. If this is possible. If not, your last suggestion would work fine(the shift key and mouse click). I appreciate your help. I hope your not getting frustrated with me.

Thanks,
Sam
 
Status
Not open for further replies.

Part and Inventory Search

Sponsor

Back
Top