473,326 Members | 2,102 Online
Bytes | Software Development & Data Engineering Community
Post Job

Home Posts Topics Members FAQ

Join Bytes to post your question to a community of 473,326 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 8388
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...
0
by: ryjfgjl | last post by:
ExcelToDatabase: batch import excel into database automatically...
0
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
1
isladogs
by: isladogs | last post by:
The next Access Europe meeting will be on Wednesday 6 Mar 2024 starting at 18:00 UK time (6PM UTC) and finishing at about 19:15 (7.15PM). In this month's session, we are pleased to welcome back...
0
by: jfyes | last post by:
As a hardware engineer, after seeing that CEIWEI recently released a new tool for Modbus RTU Over TCP/UDP filtering and monitoring, I actively went to its official website to take a look. It turned...
1
by: PapaRatzi | last post by:
Hello, I am teaching myself MS Access forms design and Visual Basic. I've created a table to capture a list of Top 30 singles and forms to capture new entries. The final step is a form (unbound)...
1
by: CloudSolutions | last post by:
Introduction: For many beginners and individual users, requiring a credit card and email registration may pose a barrier when starting to use cloud servers. However, some cloud server providers now...
1
by: Defcon1945 | last post by:
I'm trying to learn Python using Pycharm but import shutil doesn't work
0
by: af34tf | last post by:
Hi Guys, I have a domain whose name is BytesLimited.com, and I want to sell it. Does anyone know about platforms that allow me to list my domain in auction for free. Thank you
0
isladogs
by: isladogs | last post by:
The next Access Europe User Group meeting will be on Wednesday 3 Apr 2024 starting at 18:00 UK time (6PM UTC+1) and finishing by 19:30 (7.30PM). In this session, we are pleased to welcome former...

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.