Click here to Skip to main content
Sign Up to vote bad
good
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

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

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
Your Filters
Interested
Ignored
     
0 Christian Graus 533
1 Ron Beyer 326
2 Tadit Dash 253
3 samadhan_kshirsagar 229
4 OriginalGriff 198
0 Sergey Alexandrovich Kryukov 7,041
1 Prasad_Kulkarni 3,815
2 OriginalGriff 3,557
3 _Amy 3,372
4 CPallini 3,034


Advertise | Privacy | Mobile
Web01 | 2.6.130619.1 | Last Updated 17 Dec 2012
Copyright © CodeProject, 1999-2013
All Rights Reserved. Terms of Use
Layout: fixed | fluid