943,694 Members | Top Members by Rank

Ad:
  • C# Discussion Thread
  • Marked Solved
  • Views: 8597
  • C# RSS
Sep 17th, 2008
0

Deleting of the last row in DataGridView

Expand Post »
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
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matejkralik is offline Offline
24 posts
since Sep 2008
Sep 17th, 2008
0

Re: Deleting of the last row in DataGridView

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
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Sep 17th, 2008
0

Re: Deleting of the last row in DataGridView

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matejkralik is offline Offline
24 posts
since Sep 2008
Sep 17th, 2008
0

Re: Deleting of the last row in DataGridView

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?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Sep 24th, 2008
0

Re: Deleting of the last row in DataGridView

hi
if u want to delete row
give like this

dataGridView1.Rows.RemoveAt(dataGridView1.CurrentRow.Index);
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Sep 24th, 2008
0

Re: Deleting of the last row in DataGridView

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?
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matejkralik is offline Offline
24 posts
since Sep 2008
Sep 24th, 2008
0

Re: Deleting of the last row in DataGridView

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
Reputation Points: 10
Solved Threads: 23
Junior Poster
Renukavani is offline Offline
123 posts
since Jul 2008
Sep 24th, 2008
0

Re: Deleting of the last row in DataGridView

Would not the row index be higher than the record count?
Reputation Points: 196
Solved Threads: 190
Posting Virtuoso
LizR is offline Offline
1,735 posts
since Aug 2008
Sep 24th, 2008
0

Re: Deleting of the last row in DataGridView

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.
Reputation Points: 10
Solved Threads: 0
Newbie Poster
matejkralik is offline Offline
24 posts
since Sep 2008
May 24th, 2010
-1
Re: Deleting of the last row in DataGridView
DataGridView.Rows.RemoveAt(DataGridView.LastRpw);
Reputation Points: 9
Solved Threads: 0
Newbie Poster
syedkamran is offline Offline
1 posts
since May 2010

This thread is solved

Either the thread starter or a moderator has marked this thread as solved. You can most likely trust the responses and answers given. There is most likely no reason for any further responses to be posted here. If you have a related question, please start a new thread in this forum instead.

This thread is more than three months old

No one has posted to this discussion for at least three months. Please let old threads die and do not reply to them unless you feel you have something new and valuable to contribute that absolutely must be added to make the discussion complete. Otherwise, please start a new thread in this forum instead.
Message:
Previous Thread in C# Forum Timeline: month and day are swapped
Next Thread in C# Forum Timeline: Working with duplicate characters in a string





About Us | Contact Us | Advertise | Acceptable Use Policy
Forum Index | Build Custom RSS Feed


Follow us on Twitter


© 2011 DaniWeb® LLC