2014年7月13日 星期日

[RESOLVED] DataGridViewRow origin as to deleting a row in gridiview


For i = 0 To GridView1.Rows.Count - 1
Dim delrow As DataGridViewRow = GridView1.Rows(i)
If delrow.Selected = True Then
GridView1.Rows.RemoveAt(i)
End If
Next

This is converted C# code to vb.net code according to this post
http://forums.asp.net/t/1814535.aspx/1


I get an error at DataGridViewRow, type not defined.  Tried importing System.Object but that didn't help.  I guess I need to add the assembly for system.windows.forms, but according to this article

http://stackoverflow.com/questions/8508694/imports-system-windows-forms-in-vb-asp-net-class-file
, its not a good idea in a web project.


I'm just trying to delete a row manually in code behind in a gridview.




Are you using an asp.net gridview control? 





MetalAsp.Net



Are you using an asp.net gridview control? 





Yes, but need to delete the "selectedrow" from a button since need to do a bunch of other delete and clean up to make the gui more one button oriented.



Then you need to use GridViewRow.



GridViewRow does not have a selected property.  Compiler says there is also no "SelectedRow" property eventhough on the web it says otherwise.


If delrow.Selected
= True
Then



I had to give up on it and try it a different way.



Hi,


You can access gridview selected row index like this


int i=GridView1.SelectedRow.RowIndex-1;

then remove it.


Hope it can help you



Hi all,


I think this problem should be deeply thought about——When a row is removed, NOTICE that the successor row will be instead of this, and its index should be its original one -1. So in your loop of "for"——Do u think you can continue to use i stepped
by 1?


沒有留言:

張貼留言