Click here to Skip to main content
15,888,000 members
Home / Discussions / C#
   

C#

 
QuestiondataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB13-Aug-10 10:27
MumbleB13-Aug-10 10:27 
AnswerRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff13-Aug-10 10:39
mveOriginalGriff13-Aug-10 10:39 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB13-Aug-10 11:02
MumbleB13-Aug-10 11:02 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB13-Aug-10 11:18
MumbleB13-Aug-10 11:18 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff13-Aug-10 22:59
mveOriginalGriff13-Aug-10 22:59 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB14-Aug-10 3:41
MumbleB14-Aug-10 3:41 
AnswerRe: dataGridView1_CellContentClick Error Index Out of Range Pin
Luc Pattyn13-Aug-10 14:00
sitebuilderLuc Pattyn13-Aug-10 14:00 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB13-Aug-10 21:50
MumbleB13-Aug-10 21:50 
Luc, to start off, thanks for reference to your article. I have done that. Thumbs Up | :thumbsup:

As for cleaning up my code, I am doing that. Thumbs Up | :thumbsup:

As for your comment about being professional, a bit uncalled for but hey some peopl have bad days.

To explain the problem:

I have a form with a dataGridView on it. I also have a button on this form that loads the data grid with data from the Database. Only three columns: One is the ID column, which is an Autonumber, and the other two are Text columns. I am adding two extra columns to the dataGridView called Edit and Delete. Now, on the dataGridView1_CellContentClick event, when I click in any of the column/rows to edit data, I get an error. Full error message being, Index was out of range. Must be non-negatuve and less than the size of the collection. Parameter name: Index".

Below is the code:
private void dataGridView1_CellContentClick(object sender, DataGridViewCellEventArgs e)
{
    int currentRow = e.RowIndex;
    int rowint = 0;
    dt.Clear();

    try
    {
        conn.Open();

        string taskstring = dataGridView1[0, currentRow].Value.ToString(); //This is where the error is.

In the above code, when a user clicks on a cell to edit the contents, the code has to do a check to see if the selected cell is an Edit or Delete Button Column. What seems to happen is that when I run this now, this morning in debug with a line break at the point where I get the error it seems to work. When running it in debug without the line break it does the following. Some times it selects the cell and other times it doesn't. However, it doesn't seem to be throwing the error. Cry | :((
Excellence is doing ordinary things extraordinarily well.

GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
Luc Pattyn13-Aug-10 22:34
sitebuilderLuc Pattyn13-Aug-10 22:34 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff13-Aug-10 23:03
mveOriginalGriff13-Aug-10 23:03 
AnswerRe: dataGridView1_CellContentClick Error Index Out of Range Pin
Luc Pattyn13-Aug-10 23:13
sitebuilderLuc Pattyn13-Aug-10 23:13 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff13-Aug-10 23:22
mveOriginalGriff13-Aug-10 23:22 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB14-Aug-10 4:18
MumbleB14-Aug-10 4:18 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff14-Aug-10 6:06
mveOriginalGriff14-Aug-10 6:06 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
MumbleB14-Aug-10 10:00
MumbleB14-Aug-10 10:00 
GeneralRe: dataGridView1_CellContentClick Error Index Out of Range Pin
OriginalGriff14-Aug-10 23:50
mveOriginalGriff14-Aug-10 23:50 
QuestionReturn a specified item from a list box.. Pin
Tichaona J13-Aug-10 8:57
Tichaona J13-Aug-10 8:57 
AnswerRe: Return a specified item from a list box.. Pin
OriginalGriff13-Aug-10 9:06
mveOriginalGriff13-Aug-10 9:06 
GeneralRe: Return a specified item from a list box.. Pin
Ravi Bhavnani13-Aug-10 9:15
professionalRavi Bhavnani13-Aug-10 9:15 
GeneralRe: Return a specified item from a list box.. Pin
Luc Pattyn13-Aug-10 9:28
sitebuilderLuc Pattyn13-Aug-10 9:28 
GeneralRe: Return a specified item from a list box.. Pin
Ravi Bhavnani13-Aug-10 9:31
professionalRavi Bhavnani13-Aug-10 9:31 
GeneralRe: Return a specified item from a list box.. Pin
Luc Pattyn13-Aug-10 9:34
sitebuilderLuc Pattyn13-Aug-10 9:34 
GeneralRe: Return a specified item from a list box.. Pin
OriginalGriff13-Aug-10 10:10
mveOriginalGriff13-Aug-10 10:10 
GeneralRe: Return a specified item from a list box.. Pin
Luc Pattyn13-Aug-10 10:22
sitebuilderLuc Pattyn13-Aug-10 10:22 
GeneralRe: Return a specified item from a list box.. Pin
OriginalGriff13-Aug-10 10:41
mveOriginalGriff13-Aug-10 10:41 

General General    News News    Suggestion Suggestion    Question Question    Bug Bug    Answer Answer    Joke Joke    Praise Praise    Rant Rant    Admin Admin   

Use Ctrl+Left/Right to switch messages, Ctrl+Up/Down to switch threads, Ctrl+Shift+Left/Right to switch pages.