Click here to Skip to main content
12,348,925 members (67,784 online)
Rate this:
 
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)
                {
                    table.Columns.Add(grdvTest.Columns[num].HeaderText);
                    num++;
                }
                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(" ", " ");
                        else
                            row2[num] = "";
                    }
                    table.Rows.Add(row2);
                }
            }

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

Please help!

here my project with C#: http://www.mediafire.com/download.php?g7vtz2973g4h59r

regard!
Posted 17-Dec-12 17:02pm
Edited 17-Dec-12 17:38pm
v2
Comments
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: http://nt3.upanh.com/b6.s34.d1/f3575568d9a71ca6c181e6d4f41066ca_51722203.error1.jpg

1 solution

Rate this: bad
 
good
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.
  Permalink  
Comments
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


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