Delete row from DataGrid via code

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
 
R

Richard Myers

Hi Jason

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

hth
Richard
 
C

Cor Ligthert

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
 
R

Richard Myers

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

Richard
 
G

Guest

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
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Top