How to delete row from datagrid 
Author Message
 How to delete row from datagrid

Hi,

I'm using DataGrid and if I press 'Delete'-button when certain row is
selected, row will be deleted as normal - but how to do this same using menu
command 'Edit/Delete' ? Can anyone help me with code sample (or link) ? I
think this must be easy, but I'm new with VB.NET.



Tue, 27 Sep 2005 18:40:43 GMT  
 How to delete row from datagrid
are you wanting to delete the data from the data source?  
i THINK that the DG is bound (ie. you can't delete a row
from the DataGrid, you must delete it from the data
source and then refresh the datagrid).

in either case you can do it this way, using a dataset.  
if you DO wish to modify the data source that this
dataset was filled from, call the .Update(ds) command (in
the dataadaptor class) later; if you just want the
datagrid to be modified, DO NOT call the .Update(ds)
method.  here's code for what you could do.

*given dg is a datagrid, ds is a dataset that has been
filled previously, and tbl is a datatable in the dataset;
and that dg.DataSource=ds, and
dg.DataMember=tbl.TableName*

Public Sub DeleteRow()
   dim intIndex as integer=dg.CurrentRowIndex

   tbl.Rows.RemoveAt(intindex)
   tbl.AcceptChanges()

   dg.Update()
End Sub

at least, that's how I would do it.  good luck, man!
ben

Quote:
>-----Original Message-----
>Hi,

>I'm using DataGrid and if I press 'Delete'-button when
certain row is
>selected, row will be deleted as normal - but how to do

this same using menu
Quote:
>command 'Edit/Delete' ? Can anyone help me with code

sample (or link) ? I
Quote:
>think this must be easy, but I'm new with VB.NET.

>.



Tue, 27 Sep 2005 20:46:01 GMT  
 How to delete row from datagrid
Heres how to delete from a datagrid....you must make sure you have bound a
delete column in the properties of the data control.

If you don't understand this give me your email address and I'll send you a
full working solution.

Phill

Private Sub DataGrid1_DeleteCommand(ByVal source As Object, ByVal e As
System.Web.UI.WebControls.DataGridCommandEventArgs) Handles
DataGrid1.DeleteCommand

Dim cnn As SqlConnection
Dim cmd As SqlCommand

cnn = New SqlConnection("data source=Uks2150;initial catalog=Licensing;User
ID=sa;Password=zrf99dlnfk;persist security info=True")

cnn.Open()
cmd = New SqlCommand()

Dim licid As Integer

licid = Integer.Parse(e.Item.Cells(1).Text)
cmd.CommandText = "delete from STGLicensing where Licenseid=" & licid

cmd.Connection = cnn
cmd.ExecuteNonQuery()
BindGrid() - function that rebinds the data

End Sub


Quote:
> are you wanting to delete the data from the data source?
> i THINK that the DG is bound (ie. you can't delete a row
> from the DataGrid, you must delete it from the data
> source and then refresh the datagrid).

> in either case you can do it this way, using a dataset.
> if you DO wish to modify the data source that this
> dataset was filled from, call the .Update(ds) command (in
> the dataadaptor class) later; if you just want the
> datagrid to be modified, DO NOT call the .Update(ds)
> method.  here's code for what you could do.

> *given dg is a datagrid, ds is a dataset that has been
> filled previously, and tbl is a datatable in the dataset;
> and that dg.DataSource=ds, and
> dg.DataMember=tbl.TableName*

> Public Sub DeleteRow()
>    dim intIndex as integer=dg.CurrentRowIndex

>    tbl.Rows.RemoveAt(intindex)
>    tbl.AcceptChanges()

>    dg.Update()
> End Sub

> at least, that's how I would do it.  good luck, man!
> ben

> >-----Original Message-----
> >Hi,

> >I'm using DataGrid and if I press 'Delete'-button when
> certain row is
> >selected, row will be deleted as normal - but how to do
> this same using menu
> >command 'Edit/Delete' ? Can anyone help me with code
> sample (or link) ? I
> >think this must be easy, but I'm new with VB.NET.

> >.



Tue, 27 Sep 2005 21:36:48 GMT  
 
 [ 3 post ] 

 Relevant Pages 

1. How to delete a row in a datagrid.

2. Delete a row in a Datagrid using VB.net

3. DataGrid row delete

4. Datagrids, DataSets and deleting Rows

5. DataGrid: how to handle deleted rows

6. Delete a row from datagrid

7. Disable Delete row function in Datagrid

8. Delete Row in Datagrid

9. DELETE all rows in datagrid

10. Datagrid - Prevent Delete / New Rows

11. Cancel row deleting in DataGrid

12. Deleting a Row in Datagrid

 

 
Powered by phpBB® Forum Software