Click here to Skip to main content
13,192,207 members (32,319 online)
Rate this:
 
Please Sign up or sign in to vote.
See more:
Hi experts...I am printing data from datagridview using dataadapter and dataset...but i m getting error like There is no row at position 2...plz help me how i have to handle this...thanks

I m getting error in this statement in the following code:

((DataTable)wddgv.DataSource).Rows[i + row];



private void DrawGridBody(Graphics g, int y_value)
        {
            int x_value;
 
            for (int i = 0; i < 5; ++i)
            {
                DataRow dr =
                         ((DataTable)wddgv.DataSource).Rows[i + row];
                x_value = 0;
 
                // draw a solid line
                g.DrawLine(Pens.Black, new Point(0, y_value),
                        new Point(this.Width, y_value));
 
                foreach (DataGridViewColumn dc in wddgv.Columns)
                {
                    string text = dr[dc.DataPropertyName].ToString();
 
                    g.DrawString(text, this.Font, Brushes.Black,
                                             (float)x_value, (float)y_value + 10f);
 
                    x_value += dc.Width + 5;
                }
 
                y_value += 40;
            }
 
            row += 5;
        }
Posted 1-Mar-13 19:54pm
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 2

Your best bet would be to restrict the for block to the number of rows in the data table.

for(.int i = 0; i <= wddgv.rows.count() - 1;i++)
{
//your code here
}
  Permalink  
Rate this: bad
 
good
Please Sign up or sign in to vote.

Solution 1

before that check condition
data row count r else
u getting same error
i think database not available any values so only comng this error


DataRow dr =
((DataTable)wddgv.DataSource).Rows[i + row];
  Permalink  
Comments
Zain -Ul- Arifeen 2-Mar-13 2:20am
   
dear sir the database contains valid values.but I m getting error again and again. there is no row at position 8 or 2 or 4 etc

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 |
Web01 | 2.8.171017.2 | Last Updated 2 Mar 2013
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