Home | Contact Us | FAQ | Search & Site Map | Link to Us
Sign In | Join | Other 45 Sites in Network
HomeAnnouncementsFree MagazinesWhite PapersSubmit Content
Discussion GroupsASP.NETWindows FormsLanguages.NET FrameworkVisual Studio.NET
Articles.NET FrameworkASP.NETToolsWindows Forms
.NET DirectoryOpen Source ProjectsUser GroupsWeb Resources
Related Topics
Visual Basic 6SQL ServerMS AccessOther DB ProductsMS Server ProductsMore Topics ...

.NET Forum / Languages / C# / March 2008

Tip: Looking for answers? Try searching our database.

deleting multiple rows in a datagridview .net

Thread view: 
Enable EMail Alerts  Start New Thread
Thread rating: 
MMSJED - 18 Mar 2008 06:13 GMT
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
Cor Ligthert[MVP] - 18 Mar 2008 06:37 GMT
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

> How to let user delete multi rows from the BindingSource while the
> SelectionMode Property set to RowHeaderSelect
[quoted text clipped - 18 lines]
>
> Thank you in advance
MMSJED - 18 Mar 2008 09:10 GMT
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

> 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
[quoted text clipped - 24 lines]
> >
> > Thank you in advance
Cor Ligthert[MVP] - 18 Mar 2008 18:00 GMT
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

> Actually what I am trying to do is to give the user chance to undo changes
> by
[quoted text clipped - 58 lines]
>> >
>> > Thank you in advance
MMSJED - 18 Mar 2008 20:41 GMT
Sorry I did not get you
Please could you tell me How

Thank you in advance
mmsjed

> You have to use the delete methods which leaves the rows in the datatable
> with a rowstate deleted.
[quoted text clipped - 66 lines]
> >> >
> >> > Thank you in advance
Steve Gerrard - 19 Mar 2008 03:20 GMT
> 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.
MMSJED - 19 Mar 2008 07:03 GMT
How to fix the index is going out of range this is my main question
I believe this answer need expert

> > Sorry I did not get you
> > Please could you tell me How
[quoted text clipped - 7 lines]
> 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.

Free Magazines

Get these publications absolutely FREE for up to 12 months. There are no hidden fees and no obligation. Simply choose a title, complete the application form and submit it. Read more ...

Oracle MagazineNetwork ComputingComputer WorldBio-IT WorldeWeekInformation WeekInfosecurity
 
Sign In
Join
My Latest Posts
My Monitored Threads
My Blog
My Photo Gallery
My Profile
My Homepage

Start New Thread
Enable EMail Alerts
Rate this Thread



©2008 Advenet LLC   Privacy Policy - Terms of Use
This website includes both content owned or controlled by Advenet as well as content owned or controlled by third parties.