deleting multiple rows in a datagridview .net

  • Thread starter Thread starter MMSJED
  • Start date Start date
M

MMSJED

How to let user delete multi rows from the BindingSource while the
SelectionMode Property set to RowHeaderSelect
I have in my program datagridview bound it to sql table
Throw Bindingsource

To fill it:

MyTableTableAdaptor.fill(MyDataset.Mytable);


MyTableBindingSource.datasource = MyDataset;
MyTableBindingSource.datamember = MyDataset;


Datagridview.datasource = MyTableBindingSource;


To delete from it:

MyTableBindingSource. Removecurrent();

This only removes one item at the time so how I can let the user delete
multi selected rows

Thank you in advance
 
As I see that you use a datatable: first the question, do you want to use
remove? Remove means that it is removed from the collection, not giving the
dataadapter the change to remove it from the database?

Cor
 
Actually what I am trying to do is to give the user chance to undo changes by
calling BindingSource.CancelEdit()
And making Save button which is updating changes to the database By calling
the update Tableadaptor method so I have to call Remove or RemoveAt Or what
do u think?

To delete multiple rows in a datagridview I am using
try
{
for (int i = Main2DGrdView.SelectedCells.Count - 1; i >= 0;
i--)
{

mAIN1MAIN2RelationBindingSource.RemoveAt

(Main2DGrdView.SelectedCells.RowIndex);
}
}

catch (Exception ex)
{
MessageBox.Show("Deleted failed" + "\n" + ex.Message);
}
It raise the exception ArgumentOutOfRangeException
So how to force the program to only delete row and jump to next selected row
and deleted too
Thank you in advance
mmsjed
 
You have to use the delete methods which leaves the rows in the datatable
with a rowstate deleted.

When the update is done, the rows will be removed by the in the dataadapter
update build in AcceptChanges method which does that.

Cor

MMSJED said:
Actually what I am trying to do is to give the user chance to undo changes
by
calling BindingSource.CancelEdit()
And making Save button which is updating changes to the database By
calling
the update Tableadaptor method so I have to call Remove or RemoveAt Or
what
do u think?

To delete multiple rows in a datagridview I am using
try
{
for (int i = Main2DGrdView.SelectedCells.Count - 1; i >= 0;
i--)
{

mAIN1MAIN2RelationBindingSource.RemoveAt

(Main2DGrdView.SelectedCells.RowIndex);
}
}

catch (Exception ex)
{
MessageBox.Show("Deleted failed" + "\n" + ex.Message);
}
It raise the exception ArgumentOutOfRangeException
So how to force the program to only delete row and jump to next selected
row
and deleted too
Thank you in advance
mmsjed


Cor Ligthert said:
As I see that you use a datatable: first the question, do you want to use
remove? Remove means that it is removed from the collection, not giving
the
dataadapter the change to remove it from the database?

Cor
 
Sorry I did not get you
Please could you tell me How

Thank you in advance
mmsjed

Cor Ligthert said:
You have to use the delete methods which leaves the rows in the datatable
with a rowstate deleted.

When the update is done, the rows will be removed by the in the dataadapter
update build in AcceptChanges method which does that.

Cor

MMSJED said:
Actually what I am trying to do is to give the user chance to undo changes
by
calling BindingSource.CancelEdit()
And making Save button which is updating changes to the database By
calling
the update Tableadaptor method so I have to call Remove or RemoveAt Or
what
do u think?

To delete multiple rows in a datagridview I am using
try
{
for (int i = Main2DGrdView.SelectedCells.Count - 1; i >= 0;
i--)
{

mAIN1MAIN2RelationBindingSource.RemoveAt

(Main2DGrdView.SelectedCells.RowIndex);
}
}

catch (Exception ex)
{
MessageBox.Show("Deleted failed" + "\n" + ex.Message);
}
It raise the exception ArgumentOutOfRangeException
So how to force the program to only delete row and jump to next selected
row
and deleted too
Thank you in advance
mmsjed


Cor Ligthert said:
As I see that you use a datatable: first the question, do you want to use
remove? Remove means that it is removed from the collection, not giving
the
dataadapter the change to remove it from the database?

Cor


"MMSJED" <[email protected]> schreef in bericht
How to let user delete multi rows from the BindingSource while the
SelectionMode Property set to RowHeaderSelect
I have in my program datagridview bound it to sql table
Throw Bindingsource

To fill it:

MyTableTableAdaptor.fill(MyDataset.Mytable);


MyTableBindingSource.datasource = MyDataset;
MyTableBindingSource.datamember = MyDataset;


Datagridview.datasource = MyTableBindingSource;


To delete from it:

MyTableBindingSource. Removecurrent();

This only removes one item at the time so how I can let the user delete
multi selected rows

Thank you in advance

 
How to fix the index is going out of range this is my main question
I believe this answer need expert
 

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

Back
Top