Click here to Skip to main content
12,948,130 members (73,505 online)
Rate this:
Please Sign up or sign in to vote.
See more:
Error when click on datagridview contain data...(Row, Cells, Header)

I don't understand error!

I think problem is here in the below code...

private void CreateTable(DataGridView grdvTest, ref DataTable table)
            if (dgvResults.CurrentRow.Cells[1].Value != null)
                int num = 0;
                while (num < grdvTest.ColumnCount)
                foreach (DataGridViewRow row in (IEnumerable)grdvTest.Rows)
                    DataRow row2 = table.NewRow();
                    for (num = 0; num < row.Cells.Count; num++)
                        //row2[num] = (row.Cells[num].Value != null) ? row.Cells[num].Value.ToString().Replace(" ", " ") : "";
                        if (row.Cells[num].Value != null)
                            row2[num] = row.Cells[num].Value.ToString().Replace(" ", " ");
                            row2[num] = "";

My app: Search google => fill to datagridview => Click => Error!

Please help!

here my project with C#:

Posted 17-Dec-12 17:02pm
Updated 17-Dec-12 17:38pm
Christian Graus 17-Dec-12 23:03pm
Why are you sure there is a cells[1] ? What is the ACTUAL error message, and on what line ?
cchangkhongayngo 17-Dec-12 23:12pm
I'm not sure!
Maybe because i'm trying to read a Cells = null?
Anyone can see my project!
Here my error:

1 solution

Rate this: bad
Please Sign up or sign in to vote.

Solution 1

Try debugging and stepping through your source code.
It should lead you to the line that could actually be throwing the error.

Note that the problem could not be in the same line but in the way you are populating this data.
cchangkhongayngo 18-Dec-12 0:42am
@Abhinav: I have tried everything but can not detect the exact fault!!
please help!
cchangkhongayngo 18-Dec-12 22:19pm
anyone can not help me! :(

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

    Print Answers RSS
Top Experts
Last 24hrsThis month
OriginalGriff 5,344
CHill60 3,275
Maciej Los 2,703
Jochen Arndt 1,935
ppolymorphe 1,795

Advertise | Privacy | Mobile
Web02 | 2.8.170524.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2017
All Rights Reserved. Terms of Service
Layout: fixed | fluid

CodeProject, 503-250 Ferrand Drive Toronto Ontario, M3C 3G8 Canada +1 416-849-8900 x 100