Level Extreme platform
Subscription
Corporate profile
Products & Services
Support
Legal
Français
Deleting multiple rows from a DataGrid
Message
General information
Forum:
ASP.NET
Category:
Forms
Miscellaneous
Thread ID:
00876431
Message ID:
00876956
Views:
8
Hi Victor,

This is a probolem with the DataGrid and the best way around this is to use an ArrayList or a collection (as Bonnie pointed out) to keep track of what rows in the underlining data to delete. You delete rows from the DataTable not the DataGrid.

>Thanks Cathi.
>
>I have the following code:
>
>For i = 0 To (dv.Count - 1)
>    If Me.dgFileInfo.IsSelected(i) Then
>        dr = dv.Item(i).Row
>        strFileNumber = CType(dr("FileNumber"), String)
>        If strFileNumber = "" Then
>            dr.Delete()
>        Else
>            MessageBox.Show("Unable to delete file " & strFileNumber & ".")
>        End If
>Next
>
>I noticed that if all the rows I select in the grid have a File Number (which means none of the selected rows will be deleted), this seems to work fine. A messagebox pops up x number of times telling me I can't delete file 'xyz'. However if all (or some) of the rows do not have a File Number this doesn't work correctly. Stepping through the code I see that the first File Number it hits which equals "", gets deleted (dr.Delete). Howevever after that, the If Me.dgFileInfo.IsSelected(i) check is never true again. I have tried various combinations of records selected in the grid and every time once a record has been deleted, the IsSelected check doesn't equal true anymore.
>
>Any ideas as to what is happening?
>
>Thanks,
>
>Vic
-----------------------------------------

Cathi Gero, CPA
Prenia Software & Consulting Services
Microsoft C# / .NET MVP
Mere Mortals for .NET MVP
cgero@prenia.com
www.prenia.com
Weblog: blogs.prenia.com/cathi
Previous
Reply
Map
View

Click here to load this message in the networking platform