Removing rows from a datagrid

Bilalq

Member
Joined
Jul 21, 2004
Messages
24
Programming Experience
3-5
Hello,
Can anyone tell me if there is a way to delete/remove a row from the datagrid control which is boud to a dataset which consists of a datatable. There is not db involved here at this point. I am creating the datatable and then populating the grid from it. I can read the row and do what ever is it that I want to do, but I cannot remove the row. I have tried different things, but no luck. Any ideas?

Thanks,
 
Thanks for your reply, I tried that and also tried creating a new datatable with no rows, and that would remove everything, but the problem is when there are no more rows, it will then remove the header from datagrid as well and I want the header to show even if there are no more rows left.
 
If by header you mean the column headers; I loaded a dataGrid with data and removed all the rows yet the column headers still remained.
How are you removing the rows?
 
To remove a single row:

VB.NET:
Dim currRow As DataRow
		If datagrid1.CurrentCell.RowNumber < (datagrid1.VisibleRowCount - 1) Then
			' Set the current row using the RowNumber property of the CurrentCell.
			currRow = CType(datagrid1.DataSource, DataTable). _
			   Rows(datagrid1.CurrentCell.RowNumber)

			currRow.Delete()
end if
assuming you have a datagrid1
 
Back
Top