472,986 Members | 2,867 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 472,986 software developers and data experts.

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 8350
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 thread has been closed and replies have been disabled. Please start a new discussion.

Similar topics

3
by: David | last post by:
I was looking at this article, but it doesn't work for me. http://msdn2.microsoft.com/en-us/library/system.windows.forms.datagridview.multiselect.aspx I can not select multiple rows in my...
0
by: GS | last post by:
Hi, I have dataGridView with MultupleSelect property enabled and I programmatically set rows to be Selected based on checkbox being selected in DataGrid (code below). Issue is that it resets...
3
by: Rich | last post by:
Hello, I am populating a datagridview from a datatable and filtering the number of rows with a dataview object. Is there a way to retrieve the rows displayed by the datagridview into a separate...
3
by: manjub | last post by:
Hi, I am trying to add ability to delete multiple rows from a DataGridView in my application. When user selects multiple rows and presses delete button, I want to show a message asking to user...
9
by: Hamed | last post by:
Hello I have a DataGrid that a is bound to a DataTable. Some of the rows in the DataTable should not be deleted. How can I prohibit deleting of some identified rows? The problem could be...
7
by: =?Utf-8?B?TG9zdEluTUQ=?= | last post by:
Hi All :) I'm converting VB6 using True DBGrid Pro 8.0 to VB2005 using DataGridView. True DBGrid has a MultipleLines property that controls whether individual records span multiple lines. Is...
2
by: Brad Pears | last post by:
I am working on a new vb.net 2005 project using SQL server 2000 as the backend db. I have a listview where control I want a user to be able to select either just one or multiple rows in the...
3
by: =?Utf-8?B?S2F5xLFoYW4=?= | last post by:
In my project,i added datagridview to my form , i transfered my table to datagridview and added multiple rows and when i called dataadapther.update ,,result is ok. But when i tried it for the...
6
by: Gun Slinger | last post by:
Hi guys, I have a quick question which i have pondered for a little while. I'm not sure if its even a good idea (so maybe advice on whether or not to do it would be helpful as well). I want to...
2
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 4 Oct 2023 starting at 18:00 UK time (6PM UTC+1) and finishing at about 19:15 (7.15PM) The start time is equivalent to 19:00 (7PM) in Central...
0
by: Aliciasmith | last post by:
In an age dominated by smartphones, having a mobile app for your business is no longer an option; it's a necessity. Whether you're a startup or an established enterprise, finding the right mobile app...
0
tracyyun
by: tracyyun | last post by:
Hello everyone, I have a question and would like some advice on network connectivity. I have one computer connected to my router via WiFi, but I have two other computers that I want to be able to...
2
by: giovanniandrean | last post by:
The energy model is structured as follows and uses excel sheets to give input data: 1-Utility.py contains all the functions needed to calculate the variables and other minor things (mentions...
1
by: Teri B | last post by:
Hi, I have created a sub-form Roles. In my course form the user selects the roles assigned to the course. 0ne-to-many. One course many roles. Then I created a report based on the Course form and...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 1 Nov 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM) Please note that the UK and Europe revert to winter time on...
3
by: nia12 | last post by:
Hi there, I am very new to Access so apologies if any of this is obvious/not clear. I am creating a data collection tool for health care employees to complete. It consists of a number of...
0
isladogs
by: isladogs | last post by:
The next online meeting of the Access Europe User Group will be on Wednesday 6 Dec 2023 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, Mike...
3
SueHopson
by: SueHopson | last post by:
Hi All, I'm trying to create a single code (run off a button that calls the Private Sub) for our parts list report that will allow the user to filter by either/both PartVendor and PartType. On...

By using Bytes.com and it's services, you agree to our Privacy Policy and Terms of Use.

To disable or enable advertisements and analytics tracking please visit the manage ads & tracking page.