deleting selected row in datagrid

N

NotYetaNurd

hi i have a datagrid binded to a datatable.
i want to delete the selected record in the datagrid i did something like
this

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[CommonDataset.Tables[0]];
DataRowView row = (DataRowView) cm.Current;
row.Delete();
cm.EndCurrentEdit();
DataRow[]
dr=CommonDataset.Tables[0].Select(null,null,DataViewRowState.Deleted);
commonAdapter.Update(dr);

But somtimes the selected record is not deleted but some other record is
deleted ......
 
C

ClayB [Syncfusion]

Just something to try.

Instead of

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[CommonDataset.Tables[0]];

try

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[Grid.DataSource, Grid.DataMember];

=====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools
 
N

NotYetaNurd

actually ... i have a seperate form for adding new records ..
when i add new records and clear the dataset fill it once more then hit
delete this problem is happening (specifically happening for the every
second record i insert)
:-(



ClayB said:
Just something to try.

Instead of

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[CommonDataset.Tables[0]];

try

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[Grid.DataSource, Grid.DataMember];

=====================
Clay Burch, .NET MVP

Visit www.syncfusion.com for the coolest tools


NotYetaNurd said:
hi i have a datagrid binded to a datatable.
i want to delete the selected record in the datagrid i did something like
this

CurrencyManager cm = (CurrencyManager)
Grid.BindingContext[CommonDataset.Tables[0]];
DataRowView row = (DataRowView) cm.Current;
row.Delete();
cm.EndCurrentEdit();
DataRow[]
dr=CommonDataset.Tables[0].Select(null,null,DataViewRowState.Deleted);
commonAdapter.Update(dr);

But somtimes the selected record is not deleted but some other record is
deleted ......
 

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