468,537 Members | 1,844 Online
Bytes | Developer Community
New Post

Home Posts Topics Members FAQ

Post your question to a community of 468,537 developers. It's quick & easy.

deleting multiple rows in a datagridview .net

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
Mar 18 '08 #1
6 8044
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" <MM****@discussions.microsoft.comschreef in bericht
news:3B**********************************@microsof t.com...
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

Mar 18 '08 #2
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[i].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[MVP]" wrote:
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" <MM****@discussions.microsoft.comschreef in bericht
news:3B**********************************@microsof t.com...
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
Mar 18 '08 #3
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" <MM****@discussions.microsoft.comschreef in bericht
news:EF**********************************@microsof t.com...
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[i].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[MVP]" wrote:
>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" <MM****@discussions.microsoft.comschreef in bericht
news:3B**********************************@microso ft.com...
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

Mar 18 '08 #4
Sorry I did not get you
Please could you tell me How

Thank you in advance
mmsjed

"Cor Ligthert[MVP]" wrote:
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" <MM****@discussions.microsoft.comschreef in bericht
news:EF**********************************@microsof t.com...
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[i].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[MVP]" wrote:
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" <MM****@discussions.microsoft.comschreef in bericht
news:3B**********************************@microsof t.com...
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



Mar 18 '08 #5
MMSJED wrote:
Sorry I did not get you
Please could you tell me How
Using RemoveAt on a BindingSource will carry the deletion through to the
underlying dataset, so there is nothing wrong with using that.

I'm not sure if CancelEdit will cancel only the last RemoveAt, or all removals.
If not, you can always do RejectChanges on the entire dataset to get an undo.

Rather than SelectedCells, you should be doing SelectedRows (still going from
Count - 1 to 0). That's why your index is going out of range.
Mar 19 '08 #6
How to fix the index is going out of range this is my main question
I believe this answer need expert
"Steve Gerrard" wrote:
MMSJED wrote:
Sorry I did not get you
Please could you tell me How

Using RemoveAt on a BindingSource will carry the deletion through to the
underlying dataset, so there is nothing wrong with using that.

I'm not sure if CancelEdit will cancel only the last RemoveAt, or all removals.
If not, you can always do RejectChanges on the entire dataset to get an undo.

Rather than SelectedCells, you should be doing SelectedRows (still going from
Count - 1 to 0). That's why your index is going out of range.
Mar 19 '08 #7

This discussion thread is closed

Replies have been disabled for this discussion.

Similar topics

3 posts views Thread by David | last post: by
3 posts views Thread by manjub | last post: by
9 posts views Thread by Hamed | last post: by
7 posts views Thread by =?Utf-8?B?TG9zdEluTUQ=?= | last post: by
3 posts views Thread by =?Utf-8?B?S2F5xLFoYW4=?= | last post: by
reply views Thread by NPC403 | last post: by
By using this site, you agree to our Privacy Policy and Terms of Use.