Deleting of the last row in DataGridView

Please support our C# advertiser: $4.95 a Month - ASP.NET Web Hosting – Click Here!
Thread Solved
Reply

Join Date: Sep 2008
Posts: 24
Reputation: matejkralik is an unknown quantity at this point 
Solved Threads: 0
matejkralik matejkralik is offline Offline
Newbie Poster

Deleting of the last row in DataGridView

 
0
  #1
Sep 17th, 2008
I use button for by clicking it to delete one row in the DataGridView. This is the code:

DataGridView.Rows.RemoveAt(DataGridView.CurrentCell.RowIndex);

I use xml file as the source of dataset which is sourcedata of the DataGridView. It makes problems when I delete last row. What can I do?

pls, help
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Deleting of the last row in DataGridView

 
0
  #2
Sep 17th, 2008
Sure you want RowIndex? not RowIndex - 1?

Whats the error and did you really need to spam so many different questions, as they are all based around the same subject.. you could have placed them 1 by 1
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 24
Reputation: matejkralik is an unknown quantity at this point 
Solved Threads: 0
matejkralik matejkralik is offline Offline
Newbie Poster

Re: Deleting of the last row in DataGridView

 
0
  #3
Sep 17th, 2008
I'm sorry for spamming, won't happen again. I'm very new person in this forum and programming forum in general...

Even though, I'm not sure, that rowindex-1 is the answer for my question because rowindex points on the the exact row of the table. The deletions of other rows are successful with no errors.
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Deleting of the last row in DataGridView

 
0
  #4
Sep 17th, 2008
You havent explained the problem of the last row, the reason I wonder about -1 is becaue of the 0 based array/list properties.

What is the error you get? Is there any other code you have around that line?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 65
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: Deleting of the last row in DataGridView

 
0
  #5
Sep 24th, 2008
hi
if u want to delete row
give like this

dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 24
Reputation: matejkralik is an unknown quantity at this point 
Solved Threads: 0
matejkralik matejkralik is offline Offline
Newbie Poster

Re: Deleting of the last row in DataGridView

 
0
  #6
Sep 24th, 2008
Yes, I know, that deleting row according to currentcellindex works, but what if your selection is on the very last row in case that your property that allows users to add rows is on? That means that there are as if two last rows, one of them is traditional with some data like name, surname, age,... etc. with index [10,10], but when I tried to display the index of the row that functions to add new row via messagebox, it showed me [10,10] again. How can I distinguish between them? That one of them is impossible to delete because it serves for another purpose than displaying data from datasource?
Reply With Quote Quick reply to this message  
Join Date: Jul 2008
Posts: 65
Reputation: Renukavani is an unknown quantity at this point 
Solved Threads: 6
Renukavani Renukavani is offline Offline
Junior Poster in Training

Re: Deleting of the last row in DataGridView

 
0
  #7
Sep 24th, 2008
Originally Posted by matejkralik View Post
Yes, I know, that deleting row according to currentcellindex works, but what if your selection is on the very last row in case that your property that allows users to add rows is on? That means that there are as if two last rows, one of them is traditional with some data like name, surname, age,... etc. with index [10,10], but when I tried to display the index of the row that functions to add new row via messagebox, it showed me [10,10] again. How can I distinguish between them? That one of them is impossible to delete because it serves for another purpose than displaying data from datasource?
hi im expecting more expl if u have patients
Reply With Quote Quick reply to this message  
Join Date: Aug 2008
Posts: 1,735
Reputation: LizR has a spectacular aura about LizR has a spectacular aura about 
Solved Threads: 186
LizR LizR is offline Offline
Posting Virtuoso

Re: Deleting of the last row in DataGridView

 
0
  #8
Sep 24th, 2008
Would not the row index be higher than the record count?
Reply With Quote Quick reply to this message  
Join Date: Sep 2008
Posts: 24
Reputation: matejkralik is an unknown quantity at this point 
Solved Threads: 0
matejkralik matejkralik is offline Offline
Newbie Poster

Re: Deleting of the last row in DataGridView

 
0
  #9
Sep 24th, 2008
OK, let's close this discussion. Seems I'm confusing and complicating things alot. I used the usual way to delete: select row by clicking on row header and then hit delete.

Some things also were not working properly with my datasource and I had some raising exceptions but now it's fixed.

Let's say, that the answer is:

DataGridView.Rows.RemoveAt(DataGridView.CurrentCell.RowIndex);

It really works also when the property for adding rows is set on true as I now tried that. I don't know why it now works, but probably the problem was in my chaotic solutions for dataset as the datasource for datagridview.

I'm sorry.
Reply With Quote Quick reply to this message  
Reply

This thread has been marked solved.
Perhaps start a new thread instead?
Message:



Other Threads in the C# Forum
Thread Tools Search this Thread



About Us | Contact Us | Advertise | DaniWeb | Acceptable Use Policy | RSS Feed

©2003 - 2009 DaniWeb® LLC