Click here to Skip to main content
11,478,642 members (62,716 online)
Rate this: bad
Please Sign up or sign in to vote.
See more: C#
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 18:02pm
Edited 17-Dec-12 18:38pm
Christian Graus at 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 at 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 at 18-Dec-12 0:42am
@Abhinav: I have tried everything but can not detect the exact fault!!
please help!
cchangkhongayngo at 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
0 Sergey Alexandrovich Kryukov 205
1 F-ES Sitecore 170
2 Frankie-C 120
3 OriginalGriff 105
4 DamithSL 95
0 Sergey Alexandrovich Kryukov 7,865
1 OriginalGriff 7,341
2 Sascha Lefèvre 3,059
3 Maciej Los 2,491
4 Richard Deeming 2,335

Advertise | Privacy | Mobile
Web02 | 2.8.150520.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2015
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