Delete row from DataGrid via code

  • Thread starter Thread starter Guest
  • Start date Start date
G

Guest

If a user clicks on a row in a data grid, I would like them to be able to click a button and delete that row. I can't seem to figure out how to go about doing that. Can anyone help?

Thanks in advance,

Jason
 
Hi Jason

dim cm as CurrencyManager
cm = Me.BindingContext(me.dgMyDataGrid.Datasource)
if not cm is nothing then cm.RemoveAt(cm.current)

hth
Richard
 
Hi Richard,

I think that you seldom will use the removeAt It. It removes the data from
the dataset and makes it impossible to do an update.

Use the datarow.delete instead

http://msdn.microsoft.com/library/d...owsformscurrencymanagerclassremoveattopic.asp

Because what I sais is not mentioned above, I am not completly sure however
read below about the datarowcollection.removeAt what I think is done with
the currencymanager.removeAt

http://msdn.microsoft.com/library/d...emDataDataRowCollectionClassRemoveAtTopic.asp

I hope this helps?

Cor
 
Yep.. or just use the value of cm.current before you removeat.
Depends on what your doing Jason.

Richard
 
Thanks guys.

I actually ended up doing:

Me.DataGridView1.Rows.Remove(Me.DataGridView1.SelectedRows(0))

and then sending the update command to the datatableadapter

Thanks again,

Jason
 
Back
Top