Ok, I am going to preface this by saying that I cannot reproduce the issue you are having. However, you mentioned that the error actually occurs at dataGridView1. CurrentCell = cell which should have ruled out the -1 index error.
Ok, I am going to preface this by saying that I cannot reproduce the issue you are having. However, you mentioned that the error actually occurs at dataGridView1. CurrentCell = cell; which should have ruled out the -1 index error.
Additionally, you said that the error you get is Index -1 does not have a value. That means that even though you have the right index, cell is still coming up as index -1. This means either the cell does not exist, or something else sketchy is happening.
Since you sound like you've been at this for a while, I am assuming the cell actually exists. Since the error doesn't seem to be in any of the 4 lines you've posted I would say take a look somewhere else, like when you first bind the source to the datagridview. Update: I just found a few links relating to this.
Since I don't know how you bound your datagridview, I don't really know if any of these apply, but if any do, let us know! In any case, it seems like it may apply to binding. From: SO Question 1 If you initially bind an empty collection that does not inform the DGV of changes (e.g. A Collection does not, but a BindingList does), the initial current row offset will be correctly set to -1, (Because it is empty.
) When you subsequently add objects to your data bound collection they will still display correctly on the grid, but the CurrencyManager will not be informed of any changes, and the current row offset will remain stubbornly at -1. So, when you try to edit a row, the CurrencyManager thinks you are trying to edit a row at offset -1, and the exception is thrown.To combat this, you need to rebind before interacting with a row, or initially bind a Collection etc when it contains one or more items. SO Question 2 .
NET Monster Question.
That's what I was looking for! Thank you very much! – ErocM Apr 9 at 14:50.
Check the rowcount first, to make sure that you don't try to access a negative row number when there aren't any rows. Var c = dataGridView1. RowCount; if(c>0){ DataGridViewCell cell = dataGridView1.
Rowsc-1. Cells0; dataGridView1. CurrentCell = cell; dataGridView1.
BeginEdit(true); }.
My RowCount = 1, I added a wrapper to it and it doesn't stop the message. I have to have the code mixed up somewhere... – ErocM Apr 4 at 15:16.
Your problem lies in this piece of code: var c = dataGridView1. RowCount; DataGridViewCell cell = dataGridView1. Rowsc-1.
Cells0; When the rowcount equals zero. Then it will throw an error because dataGridView1. Rows-1 does not exist.
My RowCount = 1, I already knew that is where the issue is since that's where I am getting the message. – ErocM Apr 4 at 15:15 Dude, -1?... You can ask 100 programmers this same question and they will give you my exact answer. – Evan Larsen Apr 4 at 17:11 1.
The rowcount does not equal zero or -1. I said that already. 2.
You were stating the obvious by telling which line has the issue. – ErocM Apr 7 at 17:44.
Check the rowcount first, to make sure that you don't try to access a negative row number when there aren't any rows.
I cant really gove you an answer,but what I can give you is a way to a solution, that is you have to find the anglde that you relate to or peaks your interest. A good paper is one that people get drawn into because it reaches them ln some way.As for me WW11 to me, I think of the holocaust and the effect it had on the survivors, their families and those who stood by and did nothing until it was too late.