Click here to Skip to main content
15,889,281 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
ID = Convert.ToInt32(dataGridView1.Rows[e.RowIndex].Cells[0].Value.ToString());
TitalcomboBox.Text = dataGridView1.Rows[e.RowIndex].Cells[1].Value.ToString();
NametxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[2].Value.ToString();
HPtxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
//CPtxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[4].Value.ToString();
//WPtxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[5].Value.ToString();
//AddrstxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[6].Value.ToString();
//CitytxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[7].Value.ToString();
//StatecomboBox.Text = dataGridView1.Rows[e.RowIndex].Cells[8].Value.ToString();
//PintxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[9].Value.ToString();
//PEmailtxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[10].Value.ToString();
//WEmailtxtBox.Text = dataGridView1.Rows[e.RowIndex].Cells[11].Value.ToString();
//GendrcomboBox.Text = dataGridView1.Rows[e.RowIndex].Cells[12].Value.ToString();
//dateTimePicker1.Text = dataGridView1.Rows[e.RowIndex].Cells[13].Value.ToString();
//dateTimePicker2.Text = dataGridView1.Rows[e.RowIndex].Cells[14].Value.ToString();


What I have tried:

Index was out of range. Must be non-negative and less than the size of the collection.
Posted
Updated 17-Jan-17 22:39pm
Comments
Kornfeld Eliyahu Peter 18-Jan-17 3:45am    
On which line?

Well, the error message is clear: you are trying to access a not existing array item.
For instance, if the error occurs in
Quote:
dataGridView1.Rows[e.RowIndex].Cells[3].Value.ToString();
then the Cells array probably has just 3 items (just 0,1,2 are valid indices).
 
Share this answer
 
Comments
Jitendra shekhawat 18-Jan-17 4:48am    
what to do ....?/
slove this problems
CPallini 18-Jan-17 4:57am    
Find the offending line (use the debugger or simply read carefully the whole error message) and then try to understand why the expected item is missing.
Jitendra shekhawat 18-Jan-17 5:09am    
i understand problem...
but how to slove this....;(
Jitendra shekhawat 18-Jan-17 5:10am    
https://www.codeproject.com/Questions/1166191/Index-was-out-of-range-Must-be-non-negative-and-le?tab=mostrecent


Complete code this link
Use the debugger to see what your code is doing. It allow you to execute lines 1 by 1 and to inspect variables as it execute.
When error occurs, you will be able to inspect the array, its size and value of the index you use to access it.

Debugger - Wikipedia, the free encyclopedia[^]
Mastering Debugging in Visual Studio 2010 - A Beginner's Guide[^]

The debugger is here to show you what your code is doing and your task is to compare with what it should do.
There is no magic in the debugger, it don't find bugs, it just help you to.
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900