Click here to Skip to main content
14,739,205 members
Please Sign up or sign in to vote.
1.00/5 (1 vote)
See more:
i m using datagridview with listbox control ............... i used the below code for binding data from table to a datagridview column....
public void getGvDetailsIntoTable1()
       {
           try
           {
               int x = newDataGridView1.Rows.Count;

               for (int i = 0; i <=x-1; i++)
               {

                   QuotGridDetails1.Rows[i]["QuotationId"] = txtQuotationId.Text.Trim().ToString();
                   QuotGridDetails1.Rows[i]["QuotationDetailsId"] = dGridDetails.Rows[i].Cells["QuotationDetailsId"].Value;
                   QuotGridDetails1.Rows[i]["ItemDescription1"] = dGridDetails.Rows[i].Cells["ItemDescription1"].Value;
                   QuotGridDetails1.Rows[i]["Range1"] = dGridDetails.Rows[i].Cells["Range1"].Value;
                   QuotGridDetails1.Rows[i]["LeastCount1"] = dGridDetails.Rows[i].Cells["LeastCount1"].Value;
               }
           }
           catch (Exception ee)
           {
               MessageBox.Show(ee.Message);
           }
       }

While Executing these Statement i M Getting error like
There is no row at Position 0
.Any Solution Please.............
Posted
Updated 4-Jan-12 19:03pm
v2
Comments
   
Please do not re-post!
--SA

1 solution

The error says that that no results were returned from your query. Put your code block in if condition. something like..

if (newDataGridView1.Rows.Length > 0)
{
}
   
Comments
   
Simple, isn't it? My 5.
--SA

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




CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900